角路由在托管的应用程序上无法正常工作

时间:2019-08-02 17:09:08

标签: angular web-hosting

我将我的应用托管在strato上,但是路由无法正常工作。

from ... myapp.com,当我单击将我重定向到其他组件的按钮时,它在应用程序中起作用,但是如果我输入诸如... myapp.com/home之类的路径,则无法运行。

这些是我的路线:

const routes: Routes = [
  {path: "home", component: HomeComponent},
  {path: 'user-information', component: UserInformationComponent},
  {
    path: '',
    redirectTo: '/home',
    pathMatch: 'full'
  },
  {path: '**', component: HomeComponent}
];

当我输入一些随机路径时:

enter image description here

1 个答案:

答案 0 :(得分:1)

在应用程序路由模块中,您必须在@NgModule中添加{enableTracing:false,useHash:true}

@NgModule({imports: [RouterModule.forRoot(routes, { enableTracing: false, useHash: true})],  exports: [RouterModule]})

如果需要设置默认路由,可以使用

{path: '**' , component: YourComponent}
相关问题