我正在使用 AngularJS (1.4) 构建一个应用程序,但我遇到了 angular-ui-router 的问题。
我有这条路线:
{
name: 'personal_payment',
url: '/:personalLink',
templateUrl: 'personal_payment/personal_payment.html',
data: {
needAuth: false,
noBackground: true
}
}
然后在路由定义的末尾我有这行代码:
states.forEach(function(state) {
$stateProvider.state(state);
});
问题是现在每个页面(例如/login、/dashboard)都被误认为是 :personalLink 参数。使用 ngRoute 时,首先定义/login 路由,然后定义/:personalLink 路由就足够了,但使用 Angular-ui-router 时,它似乎不起作用,因为/:personalLink 路由是数组的最后一个路由。
我错过了什么?
编辑:我注意到只有/login 路由不起作用,对于所有其他路由,解析顺序都是正确的。我想我对这条特定的路线有一些问题!
这是/login 路由定义:
{
name: 'login',
url: '/login',
templateUrl: 'login/login.html',
data: {
needAuth: false,
noBackground: false
}
},
即使 Controller 为空,该路线也不起作用:
'use strict';
angular.module(
'myApp.login', ['ui.router']
).
controller('LoginCtrl', ["$rootScope", function($rootScope) {
}]);
模板如下:
<div class='landing1'>
<div class='landingbox' style='min-height: 386px'>
<div ng-controller="LoginCtrl" class='below-header'>
LOGIN PAGE
</div>
</div>
<div class="stripebadge">
<a href='https://herokuapp.com/privacy' target="_blank" class='light-text font-montserrat' style='font-size: 12px; margin-left: 7px'>Privacy Policy</a>
<a href="mailto:info@paylinko.com?Subject=Paylinko%20Support%20" class='light-text font-montserrat' style='font-size: 12px; margin-left: 22px;'>Contact</a><br>
<img src="assets/images/stripebadge.svg" width="185" align="center" style='margin-top: 10px; margin-bottom: 6px;'><br>
<span class='light_text' style='font-size: 12px;'>
<br>
Copyright © 2016 Paylinko, all rights reserved.</span>
</div>
<div ng-include="'footer_pl.html'"></div>
</div>
其他路线都可以,我真的不知道这条路线出了什么问题。
最佳答案
第一个参数是名称,因此:
states.forEach(function(state) {
$stateProvider.state(state.name, state);
});
关于javascript - Angular-ui-router url 被误认为是参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40404896/