我正在尝试在我的 angular 2 应用程序上延迟加载一些模块,但是当我转到特定模块的路由时,GET 请求似乎被搞砸了。
app-routing.module.ts
const routes = [
{path: 'products', loadChildren: './products/products.module#ProductsModule'},
{path: 'user', loadChildren: './user/user.module#UserModule'},
{path: '**', redirectTo: '/products'}
]
product-routing.module.ts
const routes: Routes = [
{path: '', component: ProductsComponent}
];
用户路由.module.ts
const routes: Routes = [
{path: 'login', component: LoginComponent},
{path: 'register', component: RegisterComponent},
{path: 'reset-password', component: ResetPasswordComponent},
{path: 'profile', component: ProfileComponent}
];
产品路线工作正常,但用户路线似乎不起作用,我认为这是由于以下控制台错误:
GET http://localhost:4200/user/inline.bundle.js net::ERR_ABORTED
出于某种原因,用户被添加到 url 中以获取我的所有资产。我猜我在路由方面做错了什么,但我不完全确定是什么?
你有没有''
在用户模块空路径?您应该为您的用户模块创建一些重定向空传递,因为您的路径位于/user/
UserModule 延迟加载时,并且没有到它的路由。
用户路由.module.ts
const routes: Routes = [
{path: '', redirectTo: 'login', pathMatch: 'full'},
{path: 'login', component: LoginComponent},
{path: 'register', component: RegisterComponent},
{path: 'reset-password', component: ResetPasswordComponent},
{path: 'profile', component: ProfileComponent}
];
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句