【发布时间】:2017-04-08 08:47:25
【问题描述】:
从 ng1 转移到 ng2,我想继续使用anchor hash '#' 进行路由。
afaik, ng2 使用默认的PathLocationStrategy,其中我们定义了一个<base-href="/">,它是angular 2 路由器用于客户端路由的基本路径,记录在here。
由于我使用的是 HashLocationStrategy,如果我从 index.html 中删除 <base-href=""> 会有任何问题吗? 我已经创建了一个带有以下路由的小应用程序,它似乎工作正常。
export const ROUTES: Routes = [{
path: '', redirectTo: 'login', pathMatch: 'full'
}, {
path: 'app', component: AppComponent
}, {
path: 'login', component: LoginComponent
}, {
path: 'error', component: ErrorComponent
}
];
谢谢,
【问题讨论】:
-
无论如何应该是
<base-href="/">。 AFAIK 你不需要它HashLocationStrategy -
@GünterZöchbauer 已编辑,感谢您的确认。
-
本次QA为您详细介绍stackoverflow.com/questions/38265536/…