In app.js there are a lot of things. But releavant parts are:
.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;
}
Routes are defined in files like: name.route.js
A route named unit.route.js contains:
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;
});
A route named case.route.js contains:
define([],function(){
function routeConfiger($stateProvider){
$stateProvider
.state('home.viewCase', {
url: '/viewcase/:caseId',
templateUrl: 'case-view.html',
controller: 'caseViewCtrl',
controllerAs: 'caseView',
loginRequired:true
})
Now, when I open a browser and type
http://localhost/home/units/
then I see the page unit.html.
However, if I type
http://localhost/home/viewcase/50/
somewhere, a redirect takes over and redirect the page to
http://localhost/home/main
If from main page, I click on a link which has a ng-click like this:
$state.go("home.viewCase", { caseId: '50' });
Then a "local" redirect happens and the page goes to
case-view.html
Im not able to understand what stops going directly to the viewcase:id.
Why does it work for the route "units" but not for the route "case"?
Ok I found out what the issue was. it actually worked. But not locally. Locally Im using grunt. And for some reason the redirect didnt work. But on other servers, where angular is served by nginx, going directly to a specific route works.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.