在AngularJS中,我的路线设置如下:
discountLinkApp.config(['$routeProvider', '$locationProvider',
function($routeProvider, $locationProvider) {
$routeProvider.
when('/discount-links', {
templateUrl: 'js/partials/discount-links.html',
controller: 'discountLinkController'
}).
when('/register/:tag', {
templateUrl: 'js/partials/register.html',
controller: 'paymentPageController'
}).
otherwise({
redirectTo: '/discount-links'
});
//Removes the # from the URL
$locationProvider.html5Mode(true);
}]);
我的根目录结构设置如下:
├── index.php
├── js
│ ├── app.js
│ ├── controllers
│ │ └── mainCtrl.js
│ ├── partials
│ │ ├── discount-links.html
│ │ └── register.html
│ └── services
│ └── discountLinkService.js
└── views
└── index.php
对于/discount-links
路由,AngularJS会生成正确的请求:
/js/partials/discount-links.html
然而,' / register /:tag`路由决定寻找
/register/js/partials/register.html
请注意不存在的额外/register/
段,以便获得404。
我正在努力弄清楚为什么会这样。唯一的区别是两条路线之间的:tag
。
我可以将../
添加到templateUrl以使其../js/partials/register.html
,但这对我来说并不一致。
任何想法?
答案 0 :(得分:0)
这很简单。只需在templateUrl属性中使用绝对路径即可。这意味着你必须改变这个:
js/partials/discount-links.html
到此:
/js/partials/discount-links.html
它将适用于所有道路。