Angular2 Website breaks on refreshing any page other than base URL

半城伤御伤魂 提交于 2019-12-04 19:27:40

An Angular2 SPA expects 1 single entry point for the app. Without using hash location strategy any refresh of a "page" that isn't the entry point will result in a 404 (the page doesn't exist on the server).

One way to solve this is by using the HashLocationStrategy as a provider within app.module

providers: [
    {provide: LocationStrategy, useClass: HashLocationStrategy},
    ...
]

Also make sure you have a base href in your index file of / and your import statement within app.module needs to include

import {HashLocationStrategy, LocationStrategy} from "@angular/common";
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!