How to enable ExtraOptions in an Angular 17 without app routing module?

25 Views Asked by At

I'm trying to scroll to specific Section in Angular using Fragment routes:

I assumed that I must declare Extra options in my app.routes.ts

import { Routes , ExtraOptions} from '@angular/router';
import { HomeComponent } from './home/home.component';
import { ContactComponent } from './contact/contact.component';
import { NotFoundComponent } from './not-found/not-found.component';


export const routes: Routes = [
    {path: '', component: HomeComponent},
    {path: 'home', component: HomeComponent},
    {path: 'contact', component: ContactComponent},
    {path: '**', component: NotFoundComponent}
];
export const routerOptions: ExtraOptions = {
    scrollPositionRestoration: 'enabled',
    anchorScrolling: 'enabled',
};

But I have no idea of where to import routerOptions in my app.config.ts

import { ApplicationConfig } from '@angular/core';
import { provideRouter } from '@angular/router';

import { routes } from './app.routes';
import { provideClientHydration } from '@angular/platform-browser';

export const appConfig: ApplicationConfig = {
  providers: [provideRouter(routes), provideClientHydration()]
};

I assumed it works something like this because in the documentation is not clear, any Ideas?

0

There are 0 best solutions below