If you want to introduce a resolve function that will take some time to execute, you can follow these steps:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { RouterModule } from '@angular/router';
import { AppComponent } from './app.component';
import { OneComponent } from './one.component';
import { TwoComponent } from './two.component';
import { delay } from 'rxjs/operators';
import { of } from 'rxjs/observable/of';
const routes = [
{
path: 'one', component: OneComponent, resolve: {
load: 'loading'
}
},
{ path: 'two', component: TwoComponent },
]
@NgModule({
imports: [BrowserModule, FormsModule, RouterModule.forRoot(routes)],
declarations: [AppComponent, OneComponent, TwoComponent],
providers: [{
provide: 'loading',
useValue: () => of(true).pipe(delay(3000))
}],
bootstrap: [AppComponent]
})
export class AppModule { }
By implementing this routing configuration, there will be a 3-second delay whenever you navigate to the /one
route. You can also apply the same resolve function to your home component if needed.
Check out the live demo here