是否可以使用PathLocationStrategy和一些HashLocationStrategy?
例如,登录名将没有任何哈希值,其余页面将在URL中包含哈希值。
目前我看不到一种简单的方法。所有这些都有或没有哈希,如下例所示:
@NgModule({
imports: [
RouterModule.forRoot(LAYOUT_ROUTES, { useHash: false , enableTracing: DEBUG_INFO_ENABLED })
],
exports: [
RouterModule
]
})
谢谢
答案 0 :(得分:0)
我在这里找到了我想要的内容:Angular2 - APP_BASE_HREF with HashLocationStrategy
我使用了CustomLocationStrategy并根据我的需要更改了URL
import { Injectable } from '@angular/core';
import { HashLocationStrategy } from '@angular/common';
@Injectable()
export class CustomLocationStrategy extends HashLocationStrategy {
prepareExternalUrl(internal: string): string {
let url = this.getBaseHref() + '/#' + internal;
if (internal === '/login') {
url = this.getBaseHref() + internal;
}
return url;
}
}
和index.html
...
<base href="./" />
...