Home route in ui-router

后端 未结 4 1773
陌清茗
陌清茗 2021-02-13 18:11

I use https://github.com/angular-ui/ui-router library. When I try to access index route (\'/\') I\'m redirected to 404. The code:

angular.module(\'cr\').config(f         


        
4条回答
  •  孤独总比滥情好
    2021-02-13 18:40

    Here by example:

    // the known route, with missing '/' - let's create alias
    $urlRouterProvider.when('', '/');
    
    // Redirect any unmatched url to 404 view (without change location.hash)
    $urlRouterProvider.otherwise(function($injector) {
        var $state = $injector.get('$state');
        $state.go('404', null, {
            location: false
        });
    
    }); 
    
    $stateProvider
        // homepage views
        .state('homepage', {
            url: "/",
            templateUrl: "views/homepage.html",            
            data: {
                pageTitle: 'Home'
            }
            ... more here ...
        })
        // 404 views
        .state('404', {
            url: "/404",
            templateUrl: "views/404.html",            
            data: {
                pageTitle: '404 Not found'
            }
        });
    

提交回复
热议问题