我無法專注于 routerLink。
第一行顯示了具有理論重點但不關注任何內容的完美 URL。第二行對焦很好,但會重新加載整個頁面。我可以做些什么來使用 routerLink 并專注于特定的輸入?
來源:組件1
<a [routerLink]="'first'" fragment="name"> first </a>
<a href="{{ '/first#name' }}"> first </a>
目標:組件2
<input
#name
id="name"
matInput
(ngModelChange)="change()"/>
uj5u.com熱心網友回復:
anchorScrolling
在您的應用程式路由模塊中啟用。
const routes: Routes = [{ ... }];
@NgModule({
imports: [RouterModule.forRoot(routes, { anchorScrolling: 'enabled' })],
exports: [RouterModule],
})
export class AppRoutingModule {}
我不知道為什么默認情況下禁用此功能。
如果鏈接可以多次點擊,您也必須設定onSameUrlNavigation
為'reload'
。
const routes: Routes = [{ ... }];
@NgModule({
imports: [
RouterModule.forRoot(routes, {
anchorScrolling: 'enabled',
onSameUrlNavigation: 'reload',
}),
],
exports: [RouterModule],
})
export class AppRoutingModule {}
在此處查看所有選項:https ://angular.io/api/router/ExtraOptions
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/495085.html