【问题标题】:Angular 2 page not found when refresh刷新时找不到Angular 2页面
【发布时间】:2017-01-31 20:16:15
【问题描述】:

我有一个问题,我使用函数 enableProdMode() 将我的项目推向生产,我有一个多组件,我创建了我的路线

const appRoutes: Routes = [
  { path: '', component: HomeComponent, pathMatch: 'full' },
  { path: 'formations', component: FormationComponent },
  { path: '**', component: PageNotFoundComponent }
];

所以,我 npm start 在本地启动我的应用程序,当我完成开发时,我复制并推送到我的网站。我的应用程序没问题,我可以通过我的路线动态更改页面但是如果我刷新我的页面,例如在“/formations”中,我的浏览器说找不到 404。 我的问题是:我的页面视图可能不是 VPS 或专用服务器,我有义务使用 npm start 启动我的应用程序?

谢谢你

【问题讨论】:

  • npm start 仅用于开发目的。你需要构建它。对于前ng build

标签: javascript angularjs node.js typescript npm


【解决方案1】:

您的第一个错误仅仅是因为您没有定义空 / 路由。

第二个与角度无关。当您第一次访问 localhost:14367/crisis-center url 时,angular 没有机会参与,因为请求首先到达您的服务器 - 您需要在那里修复它。

以后请访问 gitter 频道以获取与支持相关的问题。谢谢!

【讨论】:

    猜你喜欢
    • 2021-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-06
    • 2018-05-18
    • 2017-10-06
    • 2012-12-19
    • 2019-12-24
    相关资源
    最近更新 更多