![](/img/trans.png)
[英]AngularJS - Route to another page of different ng-app module after login
[英]AngularJS redirecting to another ng-app module
这里是AngularJS的新手。
我使用Yeoman,grunt和bower创建了一个AngularJS应用程序。
索引页面包含一些样式以及ng-app和ng-view。
的index.html
<html>
<head>
<!-- CSS Imports -->
</head>
<body ng-app="MyApp1">
<div>
//Some divs here to have some styles
<div ng-view></div>
</div>
</body>
<!--importing AgularJS, app.js, controller JS files -->
</html>
app.js
'use strict';
angular.module('MyApp1', [])
.config(function ($routeProvider,$locationProvider) {
$routeProvider
.when('/', {
redirectTo: '/main'
})
.when('/invoice', {
templateUrl: 'views/invoice.html',
controller: 'UploadController'
})
.when('/main', {
templateUrl: 'views/main.html',
controller: 'MainCtrl'
})
.when('/login', {
templateUrl: 'views/login.html',
})
.otherwise({
redirectTo: '/main'
});
// $locationProvider.html5Mode(true);
});
angular.module('LoginApp', [])
.config(function ($routeProvider,$locationProvider) {
});
索引页面具有ng-view
,将显示invoice.html或main.html。 默认值为main.html
。 main.html中
<div class="hero-unit">
<a ng-href="views/login.html" target="_self">Login</a>
<br>
<a ng-href="#invoice">New Document</a>
</div>
好。 在这个main.html
,我有两个链接。 第二个是发票链接。 无论如何,它将显示在index.html ng-view
内部。 控制器UploadController
属于MyApp1模块。 并且它具有单独的JS文件。 一切正常。
第一个链接是另一个HTML页面。 其login.html 。 它还有另一个名为LoginApp的 ng-app
。 这两个模块都是独立的,并且在不同的页面中。
当我单击第一个链接时,它将转到login.html 。 但是在URL中,它显示为http://localhost:9000/views/login.html
。 但是我希望它像http://localhost:9000/login
,就像其他main.html( http://localhost:9000/#/main
)一样。 当我编辑<a ng-href="#login">Login</a>
之类的链接时,它不起作用。
还有$locationProvider.html5Mode(true);
对我不起作用。
将login.html放在与index.html相同的文件夹中。
我认为不可能路由到另一个模块。 但是,login.html的此路由规则不适用于(外部)页面。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.