Angular ui-基于父路由参数的路由器可选参数

Angular ui-router optionnal parameters based on parent route parameter

我正在尝试根据父路由参数在路由上设置可选参数

我的父路由

        .state('scoreboard', {
            url: '/scoreboard/:type/:period',
            params: {
                type: 'channels',
                period: 'daily'
            }
        })

当 :period 为 'daily'

喜欢/scoreboard/channels/daily/01/01/2000

        .state('scoreboard.daily', {
            url: '/:day/:month/:year',
            params: {
                day: "1",
                month: "1",
                year: "2000"
            }
        })

当 :period 为 'weekly'

喜欢/scoreboard/channels/weekly/01/2000

        .state('scoreboard.weekly', {
            url: '/:week/:year',
            params: {
                week: "1",
                year: "2000"
            }
        })

当 :period 为 'monthly'

喜欢/scoreboard/channels/monthly/01/2000

        .state('scoreboard.monthly', {
            url: '/:month/:year',
            params: {
                month: "1",
                year: "2000"
            }
        })

但由于 scoreboard.weekly 和 scoreboard.monthly 具有相同数量的参数,因此它们会发生冲突。

我想知道是否有一种方法可以根据父路由参数定义状态。

谢谢,对不起我的英语。

您的记分板状态应该只是 /scoreboard/:type,然后 3 个子状态可以是:

/daily/:day/:month/:year

/weekly/:week/:year

/monthly/:month/:year