How to get the route name when location changes?

后端 未结 4 993
借酒劲吻你
借酒劲吻你 2020-12-05 13:35

I defined some routes:

angular.module(\'myApp\', [])
  .config(\'$routeProvider\', function($routeProvider) {
    $routeProvider.when(\'/aaa\', { templateUrl         


        
4条回答
  •  余生分开走
    2020-12-05 14:01

    Not a very elegant solution, and I have only tested it in Chrome DevTools, but it seems to work:

    Object.getPrototypeOf($route.current) === $route.routes['/users/:id];
    

    For others wanting to use this, just replace '/users/:id' with the pattern that you used when you defined your route.

    Also if you want to match the otherwise path, just use $route.routes['null']

    Disclaimer: This is just a workaround that I found and which works for me. Given that this behavior is not documented, and that I didn't test it to see if it works in all scenarios, use it at your own risk.

提交回复
热议问题