How might I move AngularJS Routes into separate file

后端 未结 3 1831
滥情空心
滥情空心 2021-02-01 07:51

I was curious if anybody was familiar with separating routes from the main app config function. My route list is getting quite large and I wanted to move them into a separate fi

3条回答
  •  一生所求
    2021-02-01 08:30

    You can (and should !) use AngularJS modules to separate your application into modules.

    Then, each module can define its own routes (with its own .config). Then, in your main module (usually "app"), you just need to require them as dependencies and you're set to go.

    angular.module('blog', ['ngRoute'])
      .config(['$routeProvider', function ($routeProvider) {
        ...
      }];
    
    angular.module('app', ['blog', 'user']);
    

    Then you can have each module in its own file.

提交回复
热议问题