Angular 路由在托管应用程序上无法正常工作
Angular routing not working correctly on hosted app
我在 strato 上托管了我的应用程序,但路由无法正常工作。
从 ...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}
];
当我输入一些随机路径时:
在 app-routing-module 中,您必须在 @NgModule
中添加 { enableTracing: false, useHash: true}
@NgModule({imports: [RouterModule.forRoot(routes, { enableTracing: false, useHash: true})], exports: [RouterModule]})
如果你需要创建默认路由,你可以使用
{path: '**' , component: YourComponent}
我在 strato 上托管了我的应用程序,但路由无法正常工作。
从 ...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}
];
当我输入一些随机路径时:
在 app-routing-module 中,您必须在 @NgModule
中添加 { enableTracing: false, useHash: true}@NgModule({imports: [RouterModule.forRoot(routes, { enableTracing: false, useHash: true})], exports: [RouterModule]})
如果你需要创建默认路由,你可以使用
{path: '**' , component: YourComponent}