【问题标题】:Angular 2 - is base-href redundant when using HashLocationStrategyAngular 2 - 使用 HashLocationStrategy 时 base-href 是多余的
【发布时间】: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/…

标签: angular angular2-routing


【解决方案1】:

如果您在 Approute 中使用 useHash: true 则无需提供 base-href 因为它是多余的,因为两者都有助于刷新页面,但遵循不同的概念。

【讨论】:

    猜你喜欢
    • 2016-12-07
    • 2016-11-23
    • 1970-01-01
    • 1970-01-01
    • 2020-08-09
    • 1970-01-01
    • 2020-06-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多