简体   繁体   English

在 angular 中隐藏 url 路径

[英]Hiding url path in angular

I am building a route in angular as show below:我正在 angular 中构建一条路线,如下所示:

const routes: Routes = [
  {path:'home', component: HomeComponent},
  {path:'', redirectTo: 'home', pathMatch: 'full'},
  {path:'**', redirectTo: 'home', pathMatch: 'full'}
];

But when I open the webpage like http://localhost:4200/, it redirects to http://localhost:4200/home, which is the expected behavior, but I want to hide the /home at the end.但是当我打开像 http://localhost:4200/ 这样的网页时,它会重定向到 http://localhost:4200/home,这是预期的行为,但我想在最后隐藏 /home。 Please dont be limited to this example only, this is only a simple scenario.请不要仅限于这个例子,这只是一个简单的场景。 Is there any way to do it.有没有办法做到这一点。
Thanks谢谢

yes, of course.当然是。 In your code, if you navigate to a particular component, you can then use this:在您的代码中,如果您导航到特定组件,则可以使用以下命令:

this.router.navigate(['/planning/capplanning'], {
      skipLocationChange: true,
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM