首页 文章

刷新页面角度2路由器

提问于
浏览
0

我有以下网络与角度2路由(使用vs 2015作为我的IDE)
enter image description here

但是,每当我刷新页面,我得到这个:
enter image description here

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

是否有任何解决方案,所以每当我硬刷新时,它总是去http://localhost:57831/index.html而不是http://localhost:57831/index.html/search

谢谢

2 回答

  • 1

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

    在app.module.ts中:

    添加进口:

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

    在NgMoudle提供商中,添加:

    {provide: LocationStrategy, useClass: HashLocationStrategy}
    
  • 0

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

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

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

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

    也许这个文件位于这里:

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

相关问题