![](/img/trans.png)
[英]how to use routerLink instead of href in anchor tag in 'innerHTML' in angular2+?
[英]Angular - routerLink still reloading even if no href tag exists
我有以下代碼:
<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根而重新加載嗎?
檢查此stackblitz鏈接。 我創建了示例應用程序。
https://stackblitz.com/edit/routerlink-xqqztn
雖然可能不是您的情況確切,但我嘗試按照您的描述進行操作
如果這不能解決問題,請創建stackblitz鏈接
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.