How to defer routes definition in Angular.js?

前端 未结 2 727
没有蜡笔的小新
没有蜡笔的小新 2020-11-28 05:49

I have configured some basic routes that are available for all users before they log in:

App.config(function ($routeProvider) {
    $routeProvider.
        w         


        
2条回答
  •  北海茫月
    2020-11-28 06:10

    I found that the answer by @pkozlowski.opensource works only in angularjs 1.0.1. However, after angular-route.js becomes an independent file in the later version, directly set the $route doesn't work.

    After reviewing the code, I find the key of $route.routes is no longer used to match location but $route.route[key].RegExp is used instead. After I copy the origin when and pathRegExp function, route works. See jsfiddle: http://jsfiddle.net/5FUQa/1/

      function addRoute(path, route) {
         //slightly modified 'when' function in angular-route.js
      }
      addRoute('/dynamic', {
        templateUrl: 'dynamic.tpl.html'
      });
    

提交回复
热议问题