Angular 2 Router how to hide browser url parameter Id's and give alias names

好久不见. 提交于 2019-12-12 10:07:28

问题


How do I route to employeeDetail/23 but represent to the user an alias URL like /EmployeeDetails?


Background

I'm trying to implement Angular 2 routing and when I went to the detail section I see:

http://localhost:3444/employeedetail/23.

Here I want to hide that 23 on the browser URL.


Example

http://plnkr.co/edit/QgehylornOgXhTaZX8Yn?p=preview

{path: 'crisis-center/:id/:id2', component: CrisisDetailComponent}

I want to hide those IDs on the browser URL and instead present an alias route name.


回答1:


use "skipLocationChange" from where you are calling this route (assuming 23 is your empId):

this.router.navigateByUrl("/employeedetail/"+empId,  { skipLocationChange: true });


来源:https://stackoverflow.com/questions/38153623/angular-2-router-how-to-hide-browser-url-parameter-ids-and-give-alias-names

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!