[英]How to write a router.navigate method to navigate to parent module from child module in angular6
I am able to navigate from parent module to child module , in the same way i want to navigate back to the parent module from child module. 我能够从父模块导航到子模块,就像我想从子模块导航回到父模块一样。 by using only typescript router.navigate method.
通过仅使用typescript router.navigate方法。
From html view able to navigate but its not working for typescript file. 从html视图能够浏览,但不适用于打字稿文件。
for example like 例如像
this.router.navigate['../../',value1];
you can add in your routing module and object call data and pass the route you need for example 您可以在路由模块和对象调用数据中添加并传递所需的路由,例如
path: 'users',
loadChildren: 'some/route/here/here.module#HereModule',
data: { title: 'title view', urlParent: 'parentRoute' },
after you use in your child component with activatedRoute from @angular/router something like this (do not forget injection dependency of activatedRoute in your constructor) 在@ angular / router中将您的子组件与ActivateRoute一起使用后,类似这样(不要忘记在构造函数中注入ActivateRoute的依赖项)
this.urlParent = this.activatedRoute.snapshot.data.urlParent;
with that you can use your this.router.navigate[`${this.urlParent}`]
这样您就可以使用
this.router.navigate[`${this.urlParent}`]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.