angularjs ui-router strange behaviour with additional segment in route

前端 未结 2 620
梦谈多话
梦谈多话 2020-12-02 01:05

I\'m suffering a problem with ui-router when I add a wrong segment to the route.

An example... http://xxx.xxxxx.xxx/roles works fine. This is a route defined without

2条回答
  •  悲&欢浪女
    2020-12-02 01:35

    You also have to define an state that points to the otherwise url, this way UI Routers knows how to handle the default state.

    var app = angular.module('demo', ['ui.router']);
    
    
    app.config(function($stateProvider, $urlRouterProvider){
      
      $stateProvider
        .state('roles', {
          url: '/roles',
          templateUrl: 'roles.html'
      })
      
      .state('otherwise', {
         url: '/',
         templateUrl: 'otherwise.html'
       })
      
      $urlRouterProvider
            .otherwise('/');
    })
    
    
    
    

提交回复
热议问题