在app.js中有很多东西。但重要的部分是:
.config(function ($stateProvider, $urlRouterProvider, $locationProvider) {
$stateProvider
.state('home.notfound, {
url: '/notfound,
templateUrl: 'modules/main/views/404.html'
})
.state('home.unauthorized', {
url: '/unauth',
templateUrl: '/unauthorized'
});
$urlRouterProvider.otherwise('/home/main');
.run(function ($rootScope, localize, CookieService, $location) {
$rootScope.$on('$stateChangeStart', function(scope, next) {
var userCookie = CookieService.getCookie(Config.loginCookie, true);
if(next.loginRequired){
if(!userCookie){
// Logout user without cookie
$location.path('/login');
}
}
else{
return;
}
路由在以下文件中定义:name.route.js
名为unit.route.js的路线包含:
define([],function(){
function routeConfiger($stateProvider){
$stateProvider
.state('home.unit', {
url: '/units',
templateUrl: 'unit.html',
controller: 'unitCtrl',
controllerAs: 'unit',
loginRequired:true
});
}
routeConfiger.$inject=['$stateProvider'];
return routeConfiger;
});
名为case.route.js的路线包含:
define([],function(){
function routeConfiger($stateProvider){
$stateProvider
.state('home.viewCase', {
url: '/viewcase/:caseId',
templateUrl: 'case-view.html',
controller: 'caseViewCtrl',
controllerAs: 'caseView',
loginRequired:true
})
现在,当我打开浏览器并输入
时http://localhost/home/units/
然后我看到页面unit.html。
但是,如果我输入
http://localhost/home/viewcase/50/
在某处,重定向接管并将页面重定向到
http://localhost/home/main
如果在主页面上,我点击了一个像这样的ng-click的链接:
$state.go("home.viewCase", { caseId: '50' });
然后发生“本地”重定向,页面转到
case-view.html
我无法理解停止直接进入视图的内容:id。
为什么它适用于路线“单位”而不适用于路线“案例”?
答案 0 :(得分:0)
好的,我发现了问题所在。 它确实有效。但不是本地的。我当地使用咕噜声。由于某种原因,重定向不起作用。但在其他服务器上,nginx提供角度,直接进入特定路径。