我正在开发我的角应用程序,并设置了这样的路线
angular.module('app', ['ngRoute'])
.config(function ($routeProvider, $locationProvider) {
$routeProvider.when('/', {
template : "",
controller : function($window) {
$window.location.href = '/';
}
}).when('/test', {
redirectTo : '/test/dashboard'
}).when('/test/dashboard', {
templateUrl : '../partials/dashboard.html',
controller : 'DashboardController'
}).when('/test/unit', {
templateUrl : '../partials/unit.html',
controller : 'unitController'
});
$locationProvider.html5Mode(true);
});
HTML是
<body ng-app="app">
...
<div id="sidebar-wrapper" class="fill-height sidebar-nav">
<ul class="tabRow nav nav-stacked">
<li ng-class="{active: isActive('dashboard') }"><a id="dashboardLink" ng-href="#test/dashboard">Dashboard</a>
</li>
<li ng-class="{active: isActive('unit') }"><a id="unitLink" ng-href="#test/unit">Unit</a>
</li>
</ul>
</div>
...
</body>
Run Code Online (Sandbox Code Playgroud)
问题:
当我输入"/ test"时,此代码会将URL重定向到"/ test/dashboard",但该页面的html不会显示.但是,当我使用该路由刷新页面时,它会在页面的内容区域中显示html.
当我在链接之间切换时,仪表板显示,只是在第一次导航时不加载.
此外,当我将重定向更改为/ …