javascript - Angular 路线没有像我想象的那样工作

标签 javascript angularjs

我正在尝试做一些routingAngular ,到目前为止我已经成功了。然而,我遇到了一个问题。

以下行工作正常

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/

相关文章:

javascript - React-redux 在 TypeError :Cannot read property 'map' of undefined but console having all posts 中渲染帖子时出现错误

javascript - React.js 设计模式 : save editable document with multiple fields from the *parent* node

javascript - 如何更改 dnn 中的页面标题分隔符?

javascript - 在 AngularJS 中,确定应显示内部元素的最直接方法是什么?

jquery - AngularJS 比 jQuery 更快吗?

jquery - emojionearea 拾取图标未使用 ngRoute angularjs 显示

javascript - 为没有 flash 的网络商店设计拖放式网络图像配置器

javascript - 空格键不注册

javascript - 如何根据密码强度显示自定义消息

angularjs - 在表格 Angular 中正确显示 JSON