【问题标题】:AngularJs UI router URL formattingAngularJs UI 路由器 URL 格式
【发布时间】:2017-10-09 09:22:49
【问题描述】:

我正在使用angularjs-ui router 模块来管理我的状态。

我有这个结构:

$stateProvider.state('menu', {
        templateUrl: '/templates/menu/wrap.html',
        params: {
            slug: {
                value: ''
            },
            id: {
                value: null
            }
        },
        ncyBreadcrumb: {
            label: 'Menu'
        }

    }).state('menu.list', {
        url: '/:slug',
        parent: 'menu',
        params: {
            slug: {
                value: ''
            },
            id: {
                value: null
            },
            Name: {
                value: '{{Name}}'
            },
            Type: {
                value: null
            }
        },

        views: {
            // the main template will be placed here (relatively named)
            '': {
                templateUrl: '/templates/menu/main.html',
                controller: 'MenuMainCtrl as MNC'
            },

            // for column two, we'll define a separate controller
            'productList@menu.list': {
                templateUrl: '/templates/menu/productlist.html',
                controller: 'ProductListCtrl as PLC'
            },
            // for column two, we'll define a separate controller
            'navigation@menu.list': {
                templateUrl: '/templates/menu/navigation.html',
                controller: 'MenuNavigationCtrl as MN'
            },
            // for column two, we'll define a separate controller
            'cart@menu.list': {
                templateUrl: '/templates/menu/cart.html',
                controller: 'CartCtrl as CC'
            }
        },
        ncyBreadcrumb: {
            label: '{{Name}}'
        }
    }).state('menu.detail', {
            parent: 'menu.list',
            url: '/:productSlug',
            params: {
                productID: {
                    value: ""
                },
                productSlug: {
                    value: ""
                },
                productName: {
                    value: ""
                },
                Name: {
                    value: "Breakfast"
                },
                Type: {
                    value: null
                },
                MenuListItemID: {
                    value: null
                }

            },
            views: {
                '@': {
                    templateUrl: '/templates/menu/productSingle.html',
                    controller: 'ProductSingleCtrl as PSC'
                }
            },

            ncyBreadcrumb: {
                label: '{{productName}}'
            }

        });

查看名为“menu.detail”的最后一个状态。基本 URL 为“/menu/”,当此状态处于活动状态时,我的 URL 为例如。 “localhost:8081/menu/breakfast-sandwiches/farmtotable-breakfast-sandwiches”,但我的客户想成为“localhost:8081/product/farmtotable-breakfast-sandwiches”。

这甚至可能吗?如果可以,您能帮我吗?

【问题讨论】:

    标签: javascript angularjs angular-ui-router


    【解决方案1】:

    您可以通过以下方式覆盖父 URL:

    .state('menu.detail', {
        parent: 'menu.list',
        url: '^/product/:productSlug',
        params: {
            productID: {
                value: ""
            },
            productSlug: {
                value: ""
            },
            productName: {
                value: ""
            },
            Name: {
                value: "Breakfast"
            },
            Type: {
                value: null
            },
            MenuListItemID: {
                value: null
            }
    
        },
        views: {
            '@': {
                templateUrl: '/templates/menu/productSingle.html',
                controller: 'ProductSingleCtrl as PSC'
            }
        },
    
        ncyBreadcrumb: {
            label: '{{productName}}'
        }
    
    });
    

    【讨论】:

    • 我更新了“url”键,现在状态仍然有效,但 URL 是“localhost:8080/menu/product/classic-lunch-signature”。看到这个“/menu/”我想摆脱那个和url是“localhost:8080/product/classic-lunch-signature”@abhim
    • 我成功了。我刚刚将我的“”更改为“”,并且只用了几个星期,它就像一个魅力。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-03-16
    • 2023-03-30
    • 2016-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多