Home route in ui-router

后端 未结 4 1766
陌清茗
陌清茗 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:35

    You've declared how to behave when any unknown/other route is provided - go to /404.

    But we also have to define how to behave, when some expected, but not "exact" / "not known" route is accessed, ie. create alias

    That's where the .when() could/should be used:

    ...
    
    // the known route, with missing '/' - let's create alias
    $urlRouterProvider.when('', '/');
    
    // the unknown
    $urlRouterProvider.otherwise('/404');
    

提交回复
热议问题