I have route :lang/dashbaord
which set in the routes config.
How can I change the :lang
without making my page refresh?
import 'zone.js/dist/zone';
import { Component, inject } from '@angular/core';
import { CommonModule } from '@angular/common';
import { bootstrapApplication } from '@angular/platform-browser';
import { provideRouter, Router, RouterModule } from '@angular/router';
@Component({
selector: 'my-app',
standalone: true,
imports: [CommonModule, RouterModule],
template: `
<h1>Hello from {{name}}!</h1>
<a target="_blank" href="https://angular.io/start">
Learn more about Angular
</a>
<br><a [routerLink]="['/']">/</a>
<br><a [routerLink]="['/en/dashboard']">/en/dashboard</a>
<hr>
<router-outlet></router-outlet>
`,
})
export class App {
name = 'Angular';
}
@Component({
selector: 'shell',
template: `in shell <router-outlet></router-outlet>`,
imports: [RouterModule],
standalone: true,
})
export class ShellComponent {}
@Component({
selector: 'dashboard',
template: `in dashboard <button (click)="changeLang()">change lang</button>`,
})
export class DashboardComponent {
router = inject(Router);
changeLang() {
// this.router.
}
}
bootstrapApplication(App, {
providers: [
provideRouter([
{
path: ':lang',
component: ShellComponent,
children: [{ path: 'dashboard', component: DashboardComponent }],
},
]),
],
});