Handling trailing slashes in angularUI router

后端 未结 6 703
佛祖请我去吃肉
佛祖请我去吃肉 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:15

    There is a link to working plunker

    And this is the updated rule definition:

      $urlRouterProvider.rule(function($injector, $location) {
    
        var path = $location.path();
        var hasTrailingSlash = path[path.length-1] === '/';
    
        if(hasTrailingSlash) {
    
          //if last charcter is a slash, return the same url without the slash  
          var newPath = path.substr(0, path.length - 1); 
          return newPath; 
        } 
    
      });
    

    And these links will now work properly:

      
    

    The magic could be defined like this: do return changed value if there is a change... otherwise do nothing... see example

提交回复
热议问题