Angular 自定义URL路由
我试图自定义我的路由器出口路径,为我声明的路由资源添加更多标识符 以下是我宣布的路线:Angular 自定义URL路由,angular,angular9,angular-router,Angular,Angular9,Angular Router,我试图自定义我的路由器出口路径,为我声明的路由资源添加更多标识符 以下是我宣布的路线: const routes: Routes = [ { path: 'system/#/login' , component: LoginComponent }, { path: 'system/#/service', component: ServiceComponent } ]; @NgModule({ imports: [RouterModule.forRoot(routes)], ex
const routes: Routes = [
{ path: 'system/#/login' , component: LoginComponent },
{ path: 'system/#/service', component: ServiceComponent }
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
但当我启动服务器并尝试访问route/system/#/login
时,它会将我重定向到应用程序的根入口点,如localhost:4200/
,并删除我在app routing.module.ts
上与stacktrace关联的所有路径和斜线:
core.js:6241 ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'system'
Error: Cannot match any routes. URL Segment: 'system'
at ApplyRedirects.noMatchError (router.js:4396)
at CatchSubscriber.selector (router.js:4360)
at CatchSubscriber.error (catchError.js:29)
at MapSubscriber._error (Subscriber.js:75)
at MapSubscriber.error (Subscriber.js:55)
at MapSubscriber._error (Subscriber.js:75)
at MapSubscriber.error (Subscriber.js:55)
at MapSubscriber._error (Subscriber.js:75)
at MapSubscriber.error (Subscriber.js:55)
at ThrowIfEmptySubscriber._error (Subscriber.js:75)
at resolvePromise (zone-evergreen.js:798)
at resolvePromise (zone-evergreen.js:750)
at zone-evergreen.js:860
at ZoneDelegate.invokeTask (zone-evergreen.js:399)
at Object.onInvokeTask (core.js:41645)
at ZoneDelegate.invokeTask (zone-evergreen.js:398)
at Zone.runTask (zone-evergreen.js:167)
at drainMicroTaskQueue (zone-evergreen.js:569)
如果指定了当前可用的有效路径,为什么会抛出与任何URL都不匹配的错误?是否要使用哈希位置?。如果是这种情况,您需要手动设置它:
RouterModule.forRoot(routes,{useHash:true})
。如果要使用默认的PathStategy
方法,请更新路径并避免散列#
符号