在不同的文件Angularjs路由 [英] Angularjs routing in different files

查看:210
本文介绍了在不同的文件Angularjs路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要退房角路由。

<一个href=\"http://www.bennadel.com/blog/2420-Mapping-AngularJS-Routes-Onto-URL-Parameters-And-Client-Side-Events.htm\">http://www.bennadel.com/blog/2420-Mapping-AngularJS-Routes-Onto-URL-Parameters-And-Client-Side-Events.htm

实施例我看到有所有路由在同一个文件中定义。我怎么有各种途径在不同的文件/模块定义的?

THe examples I see have all the routes be defined in the same file. How do I have various routes be defined in different files / modules?

推荐答案

在AngularJS路由在配置块定义。每个模块AngularJS可以有多个配置块,你可以定义每个路线和每一个配置块。整个应用程序的最后路由是在所有模块定义的路由的总和。

In AngularJS routes are defined in configuration block. Each AngularJS module can have multiple configuration blocks and you can define routes in each and every configuration block. The final routing for the entire application is a sum of routes defined in all modules.

在实践中,你可以做到这一点,如:

In practice you can do it like:

angular.module('myModule1', []).config(function($routeProvider){
  //define module-specific routes here
});

angular.module('myModule2', []).config(function($routeProvider){
  //define module-specific routes here
});

angular.module('myApp', ['myModule1', 'myModule2']).config(function($routeProvider){
  //define app-level routes here
});

关于拆分过的文件 - 我想这在很大程度上取决于你如何分割在文件中AngularJS模块。我会建议是坚持一个文件等于一个模块的原则。

Regarding the split over files - I guess this largely depends on how you split AngularJS modules in files. What I would recommend is sticking to one-file equals one-module principle.

您可以看到这一切适用于角应用,努力打造写在AngularJS一个不平凡的应用程序的引用更大规模的Web应用程序:

You can see all this applied to a larger-scale web application in angular-app, an effort to build a reference for a non-trivial application written in AngularJS:

在提到应用程序,你可以看到在多个文件中定义的路由,例如:

In the mentioned app you can see routes defined in multiple files, ex.:

这篇关于在不同的文件Angularjs路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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