Handling trailing slashes in angularUI router

后端 未结 6 701
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-03 06:59

It\'s been hours since I started working on this problem and I can\'t seem to get my head around the solution.

I have an app that may result in users actually typing

6条回答
  •  独厮守ぢ
    2020-12-03 07:10

    You can also do it by using $urlRouterProvider.otherwise to handle the cases where the router is unable to match the path.

    In the following example, the router is unable to match /mypath and therefore calls $urlRouterProvider.otherwise to find out what to do. Here we can see the path that was requested and map it to the proper path, i.e. /mypath/

    app.config(function($urlRouterProvider) {
        $urlRouterProvider.otherwise(function ($injector, $location) {
            if ($location.$$path == '/mypath')
                return "/mypath/";
            else
                return "/defaultpath";
        });
    

提交回复
热议问题