[英]Angular routing with slash followed by hash
I have an Angular 8 project.我有一个 Angular 8 项目。 I have a route that matches to a path, let's say 'cake'.
我有一条与路径匹配的路线,比如说“蛋糕”。 My problem is when I try to access cake/#/chocolate it automatically changes the URL into cake#/chocolate.
我的问题是当我尝试访问 cake/#/chocolate 时,它会自动将 URL 更改为 cake#/chocolate。
I have noticed that if I disable the initialNavigation from the ExtraOptions of the router module the URL stays as cake/#/chocolate but then the routing doesn't take place.我注意到,如果我从路由器模块的 ExtraOptions 中禁用 initialNavigation,则 URL 将保持为 cake/#/chocolate 但路由不会发生。
Can someone let me know how I can disabled the deletion of the first slash after 'cake'?有人可以让我知道如何禁用“蛋糕”后第一个斜线的删除吗?
Thanks谢谢
You can use like this.你可以这样使用。
First Import this on app.module.ts
首先在
app.module.ts
上导入这个
import { HashLocationStrategy, LocationStrategy } from '@angular/common';
And use in provider like this并像这样在提供者中使用
providers: [ {provide: LocationStrategy, useClass: HashLocationStrategy}, ],
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.