简体   繁体   English

如何编写router.navigate方法以从angular6中的子模块导航到父模块

[英]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.

相关问题 Angular 2 router.navigate - Angular 2 router.navigate router.navigate在Angular中不起作用 - router.navigate is not working in Angular Angular2 中的 router.navigate 和 router.parent.navigate 有什么区别? - What is the difference between router.navigate and router.parent.navigate in Angular2? 如何router.navigate到Angular 4中的相同路线并捕获相同的事件? - How to router.navigate to same route in Angular 4 and catch the same event? Angular 6 router.navigate() queryParams 解析器 - Angular 6 router.navigate() queryParams parser 角度-router.navigate()不重定向到目标页面 - Angular - router.navigate() not redirecting to target page 带有查询参数的 router.navigate Angular 5 - router.navigate with query params Angular 5 为什么 Angular router.navigate() 无法导航? - Why is Angular router.navigate() not navigating? Angular 4,路由器4.0.0:routerLink或router.navigate不会以编程方式重定向到子路由 - Angular 4, Router 4.0.0: routerLink or router.navigate programatically doesn't redirect to child routes 无法使用router.navigate方法或routerlink ::导航到子路由:错误:无法匹配任何路由。 网址段:“ child2” - Cannot navigate to child routes using router.navigate method or routerlink :: Error : Cannot match any routes. URL Segment: 'child2'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM