File tree Expand file tree Collapse file tree
apps/angular/21-anchor-navigation/src/app Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { ApplicationConfig } from '@angular/core' ;
2- import { provideRouter } from '@angular/router' ;
2+ import { provideRouter , withInMemoryScrolling } from '@angular/router' ;
33import { appRoutes } from './app.routes' ;
44export const appConfig : ApplicationConfig = {
5- providers : [ provideRouter ( appRoutes ) ] ,
5+ providers : [
6+ provideRouter (
7+ appRoutes ,
8+ withInMemoryScrolling ( { anchorScrolling : 'enabled' } ) ,
9+ ) ,
10+ ] ,
611} ;
Original file line number Diff line number Diff line change @@ -8,11 +8,11 @@ import { NavButtonComponent } from './nav-button.component';
88 <nav-button href="/foo" class="fixed left-1/2 top-3">Foo Page</nav-button>
99 <div id="top" class="h-screen bg-gray-500">
1010 Empty
11- <nav-button href="# bottom">Scroll Bottom</nav-button>
11+ <nav-button fragment=" bottom">Scroll Bottom</nav-button>
1212 </div>
1313 <div id="bottom" class="h-screen bg-blue-300">
1414 I want to scroll each
15- <nav-button href="# top">Scroll Top</nav-button>
15+ <nav-button fragment=" top">Scroll Top</nav-button>
1616 </div>
1717 ` ,
1818} )
Original file line number Diff line number Diff line change 11/* eslint-disable @angular-eslint/component-selector */
22import { Component , Input } from '@angular/core' ;
3+ import { RouterModule } from '@angular/router' ;
34@Component ( {
45 selector : 'nav-button' ,
56 standalone : true ,
67 template : `
7- <a [href ]="href">
8+ <a [routerLink ]="href" [fragment]="fragment ">
89 <ng-content></ng-content>
910 </a>
1011 ` ,
1112 host : {
1213 class : 'block w-fit border border-red-500 rounded-md p-4 m-2' ,
1314 } ,
15+ imports : [ RouterModule ] ,
1416} )
1517export class NavButtonComponent {
1618 @Input ( ) href = '' ;
19+ @Input ( ) fragment : string | undefined = undefined ;
1720}
You can’t perform that action at this time.
0 commit comments