Otherwise on StateProvider

前端 未结 6 1706
粉色の甜心
粉色の甜心 2020-11-27 14:35

Using angular-ui-router, How can I use the otherwise method on $stateProvider or how can I use it at all ?

6条回答
  •  隐瞒了意图╮
    2020-11-27 15:06

    You can also manually inject $state into the otherwise function, which you can then navigate to a non-url state. This has the benefit of the browser not changing the addressbar, which is helpful for handling going back to a previous page.

        $urlRouterProvider.otherwise(function ($injector, $location) {
            var $state = $injector.get('$state');
    
            $state.go('defaultLayout.error', {
                title: "Page not found",
                message: 'Could not find a state associated with url "'+$location.$$url+'"'
            });
        });
    

提交回复
热议问题