路由器导航在导航后不保存URL
应用程序路由:
{
path: '',
component: IndexComponent,
children: [
{path: 'table', component: TimetablesStaticComponent},
{
path: 'comparison/:id',
component: TimetablesAllComponent,
children: [
{
path: 'table',
component: TimetablesStaticComponent,
},
],
},
],
},
我可以从默认根中导航到表:localhost:4200/table
,它加载了timetablesstaticcomponent。但是在服务中,我想导航到表组件并保存以前的路由。我有路由localhost:4200/comparison/123
。从服务中我调用方法this.router.navigate(['table'],{relativeto:this.activatedRoute});
它导航到localhost:4200/table
,但应为localhost:4200/comparion/123/table
我在做什么错?
app routing:
{
path: '',
component: IndexComponent,
children: [
{path: 'table', component: TimetablesStaticComponent},
{
path: 'comparison/:id',
component: TimetablesAllComponent,
children: [
{
path: 'table',
component: TimetablesStaticComponent,
},
],
},
],
},
I can navigate to table from default root: localhost:4200/table
, and it loads TimetablesStaticComponent. But in service, i'd like to navigate to table component and save previous route. I have route localhost:4200/comparison/123
. And from service i call method this.router.navigate(['table'], {relativeTo: this.activatedRoute});
And it navigates to localhost:4200/table
, but should be localhost:4200/comparison/123/table
What am i doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
ActivatedRoute
对于每个路由组件都不同。注入
timetablesAllComponent
它相对于比较/3
,在timetablestaticcomponent
中,它是beambormiss/123/table
,如果您在服务中使用它是根路由(
“”
)。您需要从组件中调用导航 - 在timetablesallcomponent
中。不是来自服务。ActivatedRoute
is different for each routed component.Injected into
TimetablesAllComponent
it is relative tocomparison/3
and inTimetablesStaticComponent
it iscomparison/123/table
If you use it in service it is the root route (
""
). You need to call the navigation from the component - in your case inTimeTablesAllComponent
. Not from the service.