Otherwise on StateProvider

前端 未结 6 1700
粉色の甜心
粉色の甜心 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 14:50

    You can with $stateProvider using the catch all syntax ("*path"). You just need to add a state config at the bottom of your list like the following one:

    $stateProvider.state("otherwise", {
        url: "*path",
        templateUrl: "views/error-not-found.html"
    });
    

    All the options are explained in https://github.com/angular-ui/ui-router/wiki/URL-Routing#regex-parameters.

    The nice thing of this option, as opposed to $urlRouterProvider.otherwise(...), is that you 're not forced to a location change.

提交回复
热议问题