刷新页面 angular 2 路由器
refresh page angular 2 router
我有以下带有 angular 2 路由的网站(使用 vs 2015 作为我的 IDE)
但是,每当我刷新页面时,我都会得到:
因此,每当我想硬刷新我的页面时,我必须先转到错误页面,然后我需要输入以下内容url:
http://localhost:57831/index.html
有没有什么解决办法,所以每当我硬刷新时,它总是去 http://localhost:57831/index.html 而不是 http://localhost:57831/index.html/search?
谢谢
此外,您应该尝试将 VC2015 网络服务器中的所有 404 请求重定向到 index.html
。如果您这样做了,那么您的问题有两种解决方案。
- 想办法更改 VC2015 应用程序的
web.conf
文件。在那里你应该找到一个 httpRuntime
条目
通过删除 :
条目将其更改为允许 :
:
<system.web>
<httpRuntime requestPathInvalidCharacters="<,>,*,%,&,\,?"/>
</system.web>
也许此文件位于此处:
%userprofile%\Documents\IISExpress\config\web.conf
- 不要在 URL 中使用
:
,使用破折号 (-
) 或上面逗号分隔列表中不违法的内容(我会说去为此),这些字符被认为是非法的是有原因的:
从这里找到答案:
在app.module.ts中:
添加导入:
import { HashLocationStrategy, LocationStrategy } from '@angular/common';
并在 NgMoudle 提供程序中添加:
{provide: LocationStrategy, useClass: HashLocationStrategy}
我有以下带有 angular 2 路由的网站(使用 vs 2015 作为我的 IDE)
但是,每当我刷新页面时,我都会得到:
因此,每当我想硬刷新我的页面时,我必须先转到错误页面,然后我需要输入以下内容url: http://localhost:57831/index.html
有没有什么解决办法,所以每当我硬刷新时,它总是去 http://localhost:57831/index.html 而不是 http://localhost:57831/index.html/search?
谢谢
此外,您应该尝试将 VC2015 网络服务器中的所有 404 请求重定向到 index.html
。如果您这样做了,那么您的问题有两种解决方案。
- 想办法更改 VC2015 应用程序的
web.conf
文件。在那里你应该找到一个httpRuntime
条目
通过删除 :
条目将其更改为允许 :
:
<system.web>
<httpRuntime requestPathInvalidCharacters="<,>,*,%,&,\,?"/>
</system.web>
也许此文件位于此处:
%userprofile%\Documents\IISExpress\config\web.conf
- 不要在 URL 中使用
:
,使用破折号 (-
) 或上面逗号分隔列表中不违法的内容(我会说去为此),这些字符被认为是非法的是有原因的:
从这里找到答案:
在app.module.ts中:
添加导入:
import { HashLocationStrategy, LocationStrategy } from '@angular/common';
并在 NgMoudle 提供程序中添加:
{provide: LocationStrategy, useClass: HashLocationStrategy}