我正在尝试做一些routing
在Angular
,到目前为止我已经成功了。然而,我遇到了一个问题。
以下行工作正常
when('/shops/:shopId/:shopName', {
但是,这条路线不起作用:
when('/shops/:shopId/:shopName/collections', {
当我导航到第二个时,我被扔到 otherwise
路线。控制台中没有显示任何错误。
我做错了什么?
根据要求提供更多路由:
when('/shops/:shopId/:shopName', {
templateUrl: 'js/modules/shops/partials/shop.html',
controller: 'ShopController',
resolve: {
shop: ['ShopService', '$route', '$q', function(ShopService, $route, $q) {
var defer = $q.defer();
ShopService.getShop($route.current.params.shopId).success(function(data) {
defer.resolve(data);
});
return defer.promise;
}]
}
}).
when('/shops/:shopId/:shopName/collections', {
templateUrl: 'js/modules/collections/partials/collections-brand.html',
controller: 'CollectionsController',
resolve: {
collections: ['CollectionService', '$route', '$q', function(CollectionService, $route, $q) {
var defer = $q.defer();
CollectionService.getCollectionsByBrand($route.current.params.shopId).success(function(data) {
defer.resolve(data);
});
return defer.promise;
}]
}
}).
/* End */
otherwise({
redirectTo: '/'
});
最佳答案
您使用的是html5模式吗?如果是这样,您可能想确保服务器上的所有内容都已正确设置,并具有正确的重定向,如果需要,您有一个基本标记等。如果正在使用它,您还可以关闭 html5Mode 以消除任何服务器设置问题。
关于javascript - Angular 路线没有像我想象的那样工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21512515/