将值传递到路由器状态

时间:2019-01-28 09:47:00

标签: angularjs angular-ui-router

在我的网络应用中,我有一个仪表板路线:

$stateProvider.state('dashboard', {
    url: '/dashboard',
    parent: 'root',
    abstract: true,
    redirectTo: 'dashboard.tasks',
    views: {
        'new@': {
            templateUrl: '/Modules/Dashboard/Dashboard.html',
            controller: 'DashboardController'
        }
    },
    onEnter: [ () => {
        console.log('dashboard enter');
        if (passedThroughValue === 'timeline') {
            console.log('dashboard enter from timeline');
        }
    }]
});

在我的timeline.html中,我具有以下链接:

ui-sref="dashboard.tasks.overview.details.information({ id: activity.task.id })"

当我单击时,我被路由到仪表板状态,并且看到dashboard enter控制台日志。但显然不是dashboard enter from timeline

如何在该链接中将字符串值传递给路由器状态,以便可以从用户导航到仪表板的地方捕获

2 个答案:

答案 0 :(得分:0)

您可以将$stateParams传递到onEnter中,然后读取其属性

onEnter: ['$stateParams', ($stateParams) => {
    console.log('dashboard enter');
    if ($stateParams.passedThroughValue === 'timeline') {
        console.log('dashboard enter from timeline');
    }
}]

使用passedThroughValue重定向时,您可以通过ui-sref

答案 1 :(得分:-1)

https://docs.angularjs.org/api/ngRoute/service/ $ routeParams [请仔细阅读本链接指南,angularjs拥有自己的RouteParam,可让您通过链接传递值]

相关问题