【发布时间】:2019-09-06 06:19:09
【问题描述】:
我有这个代码:
<a [routerLink]="['/user/', user.id]">
{{ user.username }}
</a>
这是routing.ts
// imports removed for clarity
const routes: Routes = [
{ path: '', component: MainLayoutComponent, children: [
{ path: '', component: SidebarLayoutComponent, children: [
{ path: 'feed', component: HomefeedComponent },
{ path: 'discover', component:DiscoverComponent },
]
},
{ path: 'user/:id', component: UserComponent },
]}
];
@NgModule({
imports: [ RouterModule.forRoot(routes) ],
exports: [ RouterModule ]
})
export class AppModuleRouting {}
我有两页。第 1 页和第 2 页。在两个页面中,都呈现了一个组件:user-box-component.html,其中包含上述代码。
但是在第 1 页,如果我点击“用户名”,它仍然会重新加载页面。在第 2 页中,它按预期仅重新加载 DOM。
任何想法,为什么在第 1 页,仍然发生硬重新加载?
编辑:
更多信息:如果我来到用户页面,并且 routerLink 运行良好。但是如果我去 /discover 页面,它会重新加载页面。会不会是因为没有 routerState 根而导致重新加载?
【问题讨论】:
-
显示您的第 1 页路由文件
-
@Lint 刚刚用 routing.ts 更新了问题
-
你能提供一个有效的 stackblitz 链接吗?
-
很难理解什么是实际问题。你能提供工作演示吗?
标签: javascript angular routing angular-router