【问题标题】:Angular: 404 Error Page when accessing routeAngular:访问路由时出现 404 错误页面
【发布时间】:2018-01-19 22:41:03
【问题描述】:

我有 Angular 应用程序(后端有弹簧启动)

这是我的路线:

export const routes: Routes = [
{ path: '', redirectTo: 'intro', pathMatch: 'full' },
{ path: 'home', component: HomeComponent },


// LANGUAGES
{ path: 'english', component: LanguageComponent },
{ path: 'spanish', component: LanguageComponent },

// CITIES
{ path: 'alexandria', component: CityComponent },
{ path: 'ankara', component: CityComponent }];

export const router: ModuleWithProviders = RouterModule.forRoot(routes, { useHash: false, initialNavigation: true });

现在有趣的行为:

当我在应用程序中路由时(= 单击具有 routerLink 的按钮/链接标签)一切正常,但是当我直接将 url 插入浏览器时,我得到以下信息:

  • localhost:8080/english -> Whitelabel 错误页面(默认 Spring Boot 404 页面)。 (适用于任何语言)

  • localhost:8080/alexandria -> 按预期工作(适用于任何城市)


当我在单独的服务器 (localhost:4200) 上运行前端时,一切正常。

【问题讨论】:

  • 你必须配置你的 spring boot 以将所有内容重定向到 index.html
  • 是的,我忘记了那个配置。谢谢!你把它写成答案。

标签: angular


【解决方案1】:

您必须配置您的 Spring Boot 以将所有内容重定向到 index.html

因为当请求到达你的服务器时,除非你重定向到 Angular 应用 (index.html),否则 Angular 应用不会运行,那么你在 Angular 中的路由配置就不值得了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-01-26
    • 2014-10-10
    • 1970-01-01
    • 2017-09-28
    • 2013-08-31
    • 2022-12-09
    • 2020-06-30
    • 1970-01-01
    相关资源
    最近更新 更多