在我的应用程序中,我使用了employee-details组件,当我单击返回按钮时,url看起来像http://localhost:4200/employee/123
this.router.navigate(['/'], { queryParams: { message: this.message }, relativeTo: this.activatedRoute, skipLocationChange: true });它运行良好,页面导航到所需的组件(employee-list)。但是它将员工id 123保存在url上,实际上不应该也应该看起来像http://localhost:4200/employee/。我怎样才能正确地做它。
发布于 2019-02-28 17:42:56
您可以使用this.router.navigate(['../'], {queryParams:'' relativeTo: this.route });或this.router.navigate(['employee'], {queryParams: '' });
发布于 2019-02-28 18:33:11
我认为问题出在skipLocationChange上。documentation声明了以下内容:
skipLocationChanges:无需将新状态推入历史即可导航。
我认为这正是您正在经历的情况:导航正常,但您的路线没有改变。请删除skipLocationChange。
看到这个问题画布:解决方案是使用skipLocationChanges导航到本地主机/画布,而不在url中显示'canvas‘。你想要的恰恰相反。所以我认为使用skipLocationChanges: true是你不想使用的东西。
发布于 2019-02-28 19:18:17
我通过点击https://angularfirebase.com/lessons/sharing-data-between-angular-components-four-methods/链接解决了我的问题
它有助于使用服务在页面之间传输数据a)父到子b)子到父c)兄弟到父
https://stackoverflow.com/questions/54920976
复制相似问题