AngularJs:处理两个SPA和routeProvider

时间:2015-10-06 06:56:12

标签: angularjs single-page-application

我有两个SPA:一个有<base href="/">,另一个有<base href="/dashboard/">

我将这些应用程序部署为tomcat服务器中的单独war文件。到目前为止,这是有效的。

让我们看看我的代码(第二个应用程序配置,即/ dashboard /):

myApp.config(['$routeProvider','$locationProvider', function($routeProvider, $locationProvider) {
    $locationProvider.html5Mode(true);

    $routeProvider.when('/events', {
        templateUrl: 'event-list/event-list.html',
        controller: 'eventListCtrl'
    });

    $routeProvider.when('/', {
        templateUrl: ' ',
        controller: ['$scope','$location', function($scope,$location) {
            $location.path('events');
            $location.replace(); // problem #1
        }]
    });

    $routeProvider.otherwise({redirectTo: '/404'}); // problem #2
}]);

问题#1

正如您在代码中看到的,我希望默认情况下将网址http://localhost/dashboard重定向到http://localhost/dashboard/events。但是这种配置在浏览器控制台中给出了最大调用堆栈超出错误。

问题#2

我的第一个应用中已有404页面,即http://localhost/404位置。但我目前的配置是将我重定向到http://localhost/dashboard/404。我想重用我的404页面。

请指导我正确的方向。感谢。

0 个答案:

没有答案