Pro*_*mer 7 html routes angularjs
我正在开发我的角应用程序,并设置了这样的路线
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.
当我在链接之间切换时,仪表板显示,只是在第一次导航时不加载.
此外,当我将重定向更改为/ test/unit时,它会正确重定向并显示unit.html.
不确定是什么导致了这种行为.
任何帮助,将不胜感激.
我认为你需要requireBase: false在配置 html5Mode 时指定$locationProvider
$locationProvider.html5Mode({
enabled: true,
requireBase: false
});
Run Code Online (Sandbox Code Playgroud)
这是一个工作plnkr 演示
有关与您的部署相关的更多上下文,您应该了解此表单角度文档