Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions apps/angular/21-anchor-navigation/src/app/app.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { ApplicationConfig } from '@angular/core';
import { provideRouter } from '@angular/router';
import { provideRouter, withInMemoryScrolling } from '@angular/router';
import { appRoutes } from './app.routes';
export const appConfig: ApplicationConfig = {
providers: [provideRouter(appRoutes)],
providers: [
provideRouter(
appRoutes,
withInMemoryScrolling({
anchorScrolling: 'enabled',
scrollPositionRestoration: 'enabled',
}),
),
],
};
15 changes: 13 additions & 2 deletions apps/angular/21-anchor-navigation/src/app/nav-button.component.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
/* eslint-disable @angular-eslint/component-selector */
import { Component, input } from '@angular/core';
import { Component, computed, input } from '@angular/core';
import { RouterLink } from '@angular/router';

@Component({
selector: 'nav-button',
imports: [RouterLink],
template: `
<a [href]="href()">
<a [routerLink]="routerLink()" [fragment]="fragment()">
<ng-content />
</a>
`,
Expand All @@ -14,4 +16,13 @@ import { Component, input } from '@angular/core';
})
export class NavButtonComponent {
href = input('');

isAnchorLink = computed(() => this.href().startsWith('#'));
routerLink = computed(() => {
return this.isAnchorLink() ? [] : this.href();
});

fragment = computed(() => {
return this.isAnchorLink() ? this.href().substring(1) : undefined;
});
}
4 changes: 4 additions & 0 deletions apps/angular/21-anchor-navigation/src/styles.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
@import "tailwindcss";

/* You can add global styles to this file, and also import other style files */

html {
scroll-behavior: smooth;
}
Loading