我怎么可能会移动AngularJS路由到单独的文件 [英] How might I move AngularJS Routes into separate file

查看:78
本文介绍了我怎么可能会移动AngularJS路由到单独的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很好奇,如果任何人都熟悉从主应用程序配置功能分离的路线。我的路由表越来越蛮大的,我想将其移动到一个单独的文件,并将它们加载到主配置。我已经看到了这样做过,但我不记得或者寻找在那里我看到了它。任何帮助将是AP preciated。

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 file and load them into the main config. I have seen this done before but I cannot remember or find where I saw it. Any help would be appreciated.

推荐答案

您可以(也应该!)使用AngularJS模块将应用程序分成模块。

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

然后,每个模块可以定义自己的路由(有自己的的.config )。
然后,你的主模块(通常是应用程序)中,你只需要要求他们作为依赖,你要走了。

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']);

这篇关于我怎么可能会移动AngularJS路由到单独的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆