【问题标题】:refresh page angular 2 router刷新页面 Angular 2 路由器
【发布时间】:2017-10-06 14:00:24
【问题描述】:

我有以下带有 angular 2 路由的网络(使用 vs 2015 作为我的 IDE)

但是,每当我刷新页面时,我都会得到以下信息:

因此,每当我想硬刷新我的页面时,我必须先进入错误页面,然后我需要输入以下网址: http://localhost:57831/index.html

有没有什么解决方案,所以每当我硬刷新时,它总是转到http://localhost:57831/index.html 而不是http://localhost:57831/index.html/search

谢谢

【问题讨论】:

  • 您还需要在服务器端处理路由,以便所有路由都转到您的默认页面。

标签: angular angular2-routing


【解决方案1】:

此外,您应该尝试将 VC2015 网络服务器中的所有 404 请求重定向到 index.html。如果你这样做了,有两种解决方案可以解决你的问题。

  1. 以某种方式找到更改 VC2015 应用程序的 web.conf 文件的方法。在那里你应该找到一个httpRuntime 条目

通过删除: 条目将其更改为允许:

<system.web>
    <httpRuntime requestPathInvalidCharacters="&lt;,&gt;,*,%,&amp;,\,?"/>
</system.web>

也许这个文件位于这里:

%userprofile%\Documents\IISExpress\config\web.conf
  1. 不要在你的 URL 中使用 :,使用破折号 (-) 或在上面的逗号分隔列表中不违法的内容(我会说这样做),这些字符是有原因的被认为是非法的:

【讨论】:

    【解决方案2】:

    从这里找到答案: Angular 2 : 404 error occur when i refresh through Browser

    在 app.module.ts 中:

    添加导入:

    import { HashLocationStrategy, LocationStrategy } from '@angular/common';
    

    在 NgMoudle 提供者中,添加:

    {provide: LocationStrategy, useClass: HashLocationStrategy}
    

    【讨论】:

      猜你喜欢
      • 2019-01-01
      • 2017-02-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-02
      • 1970-01-01
      相关资源
      最近更新 更多