我如何将 AngularJS 路由移动到单独的文件中 [英] How might I move AngularJS Routes into separate file

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

问题描述

我很好奇是否有人熟悉将路由与主应用程序配置功能分开.我的路由列表变得非常大,我想将它们移动到一个单独的文件中并将它们加载到主配置中.我以前见过这样做过,但我不记得或找不到我在哪里看到的.任何帮助将不胜感激.

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

然后您可以将每个模块放在自己的文件中.

Then you can have each module in its own file.

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

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