仅在AngularJS单页应用程序中的特定页面上路由配置 [英] Routes configuration only on a specific pages in AngularJS single page app

查看:92
本文介绍了仅在AngularJS单页应用程序中的特定页面上路由配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Angular开发一个具有两个模块的小型应用程序。
目标是在应用程序的不同页面上启用模块。
例如:

I am working on a small app using Angular which has of two modules. The target is to enable modules on different pages of an app. For example:

http://domain.com/app1/#routesOfApp1
http://domain.com/app2/#routesOfApp2

如何确保 routeOfApp1 http://domain.com/app2/ 上不可用?

How can I make sure that routesOfApp1 are not available on http://domain.com/app2/? Is it even possible?

我知道一种方法是创建两个完全独立的角度应用程序并分别加载它们。但是,我希望将其保留为一个大应用程序,因为在某个时候,我计划将整个过程全部转换为单页应用程序。

I know that one of the ways is to create two completely separate angular apps and load them respectively. But, I would love to keep it as a one big app, as at some point, I am planning to transition this whole thing into single page app across the board.

我有什么选择?

谢谢

推荐答案

正确地,您需要使用requirejs。当您点击 http://domain.com/app1/routesOfApp1 时,routesOfApp1.html及其angularjs控制器( routeOfApp1Controller.js)将加载。 (app2没有任何内容)

If i understand correctly you need to use requirejs. When you clicked http://domain.com/app1/routesOfApp1, routesOfApp1.html and its angularjs controller (routesOfApp1Controller.js) will load. (there is nothing for app2)

sampleApp.config(['$routeProvider',
    function($routeProvider) {
        $routeProvider.
            when('/app1/routesOfApp1', {
                templateUrl: 'app1/routesOfApp1.html',
                controller: 'routesOfApp1Controller'
            }).
            when('/app2/routesOfApp2', {
                templateUrl: 'app2/routesOfApp2.html',
                controller: 'routesOfApp2Controller'
            }).
            otherwise({
                redirectTo: '/default'
            });
}]);

http://www.codeproject.com/Articles/808213/Developing-a-Large-Scale-Application-with-a-Single

这篇关于仅在AngularJS单页应用程序中的特定页面上路由配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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