Routes configuration only on a specific pages in AngularJS single page app

安稳与你 提交于 2019-12-11 05:54:32

问题


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

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.

What are my options?

Thanks,


回答1:


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



来源:https://stackoverflow.com/questions/35451294/routes-configuration-only-on-a-specific-pages-in-angularjs-single-page-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!