Angular2路由器:如何导航到某些路径? [英] Angular2 router: how to navigate to certain path?

查看:131
本文介绍了Angular2路由器:如何导航到某些路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个模块,该模块具有其路由设置,并包含一些子模块.如何导航到从某些子级到父级或其他(兄弟)模块的某些路线?

I have module that has its routing settings and contains some children modules. How can i navigate to certain routes from some children to parent or to other (sibling) modules?

如我所见,我可以为该路由指定一个 name :

As i see I could specify a name for the route:

{ path:'/About', name: 'About',   ... }

然后使用它:

this.router.parent.navigate(['About']);

由于不赞成使用 name ,您是否知道如何使用最新版本的Angular2路由器达到相同的目的?

Since name is deprecated, do you know how can i reach the same with the latest version of Angular2 router?

推荐答案

简单使用

this.router.navigate(['/XYZ', params_here]);

或者如果您想直接重定向到路径,那么您也可以使用此

or if you want to redirect directly to path then you can also use this

this.router.navigateByUrl('/XYZ/ABC');

navigateByUrl 仅接受字符串

name在angular2 beta中已被弃用,现在路由通过将name与路径名匹配来工作

name has been deprecated in the angular2 beta i think, now the routing is working by matching name with the path name

有关更多信息,请点击此处

for more info read out here

https://angular.io/docs/ts/latest/guide/router.html

这篇关于Angular2路由器:如何导航到某些路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆