zoukankan      html  css  js  c++  java
  • Angular之ngRoute与uiRoute

    ngRoute不支持嵌套路由

    用法如下:

     1 <!DOCTYPE html>
     2 <html lang="en" ng-app="myApp">
     3 <head>
     4     <meta charset="UTF-8">
     5     <meta name="viewport" content="width = device-width, initial-scale = 1.0, maximum-scale = 1.0, user-scalable = 0" />
     6     <title>angular 路由</title>
     7 </head>
     8 <style>
     9     ul li{
    10         list-style: none;
    11         float: left;
    12         padding: 10px;
    13     }
    14 </style>
    15 <body>
    16     <ul>
    17         <li><a href="#page1">page1</a></li>
    18         <li><a href="#page2">page2</a></li>
    19         <li><a href="#page3">page3</a></li>
    20     </ul>
    21     <div ng-view></div>
    22 </body>
    23 <script src="./script/libs/angularjs.1.4.6.min.js"></script>
    24 <script src="./script/libs/angular-route.js"></script>
    25 <script>
    26     angular.module('myApp',['ngRoute'])
    27     .config(function($routeProvider){
    28         $routeProvider.when("/page1",{
    29             template:"this is page1"
    30         }).when("/page2",{
    31             template:"this is page2"
    32         }).when("/page3",{
    33             template:"this is page3"
    34         }).otherwise({
    35             redirectTo:"/page1"   //默认路由
    36         })
    37     });
    38 </script>
    39 </html>

    uiRouter支持嵌套路由

    用法如下:

     1 <!DOCTYPE html>
     2 <html lang="en" ng-app="myApp">
     3 <head>
     4     <meta charset="UTF-8">
     5     <meta name = "viewport" content = "width = device-width, initial-scale = 1.0, maximum-scale = 1.0, user-scalable = 0" />
     6     <title>angular路由</title>
     7 </head>
     8 <style>
     9     ul li{
    10         list-style: none;
    11         float: left;
    12         padding: 10px;
    13     }
    14 </style>
    15 <body>
    16     <ul>
    17         <li><a href="#page1">page1</a></li>
    18         <li><a href="#page2">page2</a></li>
    19         <li><a href="#page3">page3</a></li>
    20     </ul>
    21     <div ui-view></div>
    22 </body>
    23 <script src="./script/libs/angularjs.1.4.6.min.js"></script>
    24 <script src="./script/libs/angular-ui-router.js"></script>
    25 <script>
    26     angular.module('myApp',['ui.router'])
    27     .config(function($stateProvider,$urlRouterProvider){
    28         $stateProvider.state('page1',{
    29             url:"/page1",
    30             template:"this is p1"
    31         }).state('page2',{
    32             url:"/page2",
    33             template:"this is p2"
    34         }).state('page3',{
    35             url:"/page3",
    36             template:"this is p3"
    37         });
    38         $urlRouterProvider.otherwise('page1');
    39     });
    40 </script>
    41 </html>
  • 相关阅读:
    on duplicate key update之多列唯一索引
    js 判断 微信浏览器 安卓/苹果 pc/移动
    history 和 hash (转)
    路由vue-router
    添加图标ico
    vue项目结构
    vue2.0项目的构建
    echarts使用 图例改变和默认不选中
    微信自定义菜单设置 及 emoji表情更换
    复制/设置剪切板内容 (浏览器/nativejs)
  • 原文地址:https://www.cnblogs.com/happy1992/p/7136263.html
Copyright © 2011-2022 走看看