Angular-ui-router state.transitionTo路由到空:id(/ users //)

alo*_*ser 4 angularjs angular-ui-router

如果我手动编写网址或使用链接移动到那里,它应该路由到/users/me/而它会路由到,一切正常.但转变不会做我所期望的,我无法弄清楚为什么./users///users/me/

在我的代码中,我有:

$state.transitionTo('users.me');
Run Code Online (Sandbox Code Playgroud)

在我的路线(州)配置我有:

state('users', {
            abstract:true,

            templateUrl: '/path/to/template.html',

            access: { isPrivate: 0 },
            resolve: {
           ...a resolve block..



    }).state('users.me',{
            url: '/users/:id/',
            controller: 'userCtrl',
            access: { isPrivate: 0 },
            views:{
                'userView':{
                    templateUrl:'/path/to/template.html'',
                    controller:'userCtrl',

                },
                'view1':{
                    templateUrl:'/path/to/template.html'',
                    controller:'anotherCtrl',

                },
                'view2':{
                    templateUrl:'/path/to/template.html'',
                    controller:'anotherCtrl',

                },
                'view3':{
                    templateUrl:'/path/to/template.html'',
                    controller:'anotherCtrl',

                },
                'view4':{
                    templateUrl:'/path/to/template.html',
                    controller:'anotherCtrl'
                }
            }
Run Code Online (Sandbox Code Playgroud)

我很乐意为此提供帮助

Phi*_*mas 19

确保您提供身份证明.

$state.transitionTo('users.me', {'id': 'me'});
Run Code Online (Sandbox Code Playgroud)

这应该使它工作,但你应该使用该go()方法作为transitionTo是一个低级函数,因为0.2.0.

$state.go('users.me', {'id': 'me'});
Run Code Online (Sandbox Code Playgroud)

请务必阅读方法的文档.

  • 要清楚,`transitionTo()`不是*内部函数,它只是一个更明确和冗长的函数,而`go()`自动完成一堆事情. (2认同)