Angular 生产中路由的项目问题
Angular project problem with routing in production
我开发了一个 angular 网站:在我的 localhost:4200 测试 运行ning 中一切正常,但是当我将网站上传到我的服务器时,导航出现了大问题:
这是我的路线
const routes: Routes = [
{ path: ':id/main', component: MainComponent }
];
如您所见,如果我 运行 https://localhost:4200/test/main I access the main component but when I enter http://mywebsite/test/main 我得到一个 404 页面,我实际上可以在 localhost:4200 中使用参数 :/id 访问 "MainComponent"成立。
我该如何解决?
If the app uses the Angular router, you must configure the server to
return the application's host page (index.html) when asked for a file
that it does not have.
Clicking a link in an email, entering it in the browser address bar,
or merely refreshing the browser while on the hero detail page — all
of these actions are handled by the browser itself, outside the
running application. The browser makes a direct request to the server
for that URL, bypassing the router.
A static server routinely returns index.html when it receives a
request for http://www.sample.org/. But it rejects
http://www.sample.org/heroes/42 and returns a 404 - Not Found error
unless it is configured to return index.html instead.
有关配置serverm的更多信息,请访问angular documentation site
我开发了一个 angular 网站:在我的 localhost:4200 测试 运行ning 中一切正常,但是当我将网站上传到我的服务器时,导航出现了大问题:
这是我的路线
const routes: Routes = [
{ path: ':id/main', component: MainComponent }
];
如您所见,如果我 运行 https://localhost:4200/test/main I access the main component but when I enter http://mywebsite/test/main 我得到一个 404 页面,我实际上可以在 localhost:4200 中使用参数 :/id 访问 "MainComponent"成立。 我该如何解决?
If the app uses the Angular router, you must configure the server to return the application's host page (index.html) when asked for a file that it does not have.
Clicking a link in an email, entering it in the browser address bar, or merely refreshing the browser while on the hero detail page — all of these actions are handled by the browser itself, outside the running application. The browser makes a direct request to the server for that URL, bypassing the router.
A static server routinely returns index.html when it receives a request for http://www.sample.org/. But it rejects http://www.sample.org/heroes/42 and returns a 404 - Not Found error unless it is configured to return index.html instead.
有关配置serverm的更多信息,请访问angular documentation site