I am following the Angular Tour of Heroes Guide. I have stumbled upon the "default route" section and decided to try getting rid of the pathMatch
attribute of the Route corresponding to the empty string.
Here is how my code looks:
const routes: Routes = [
{path: 'heroes', component: HeroesComponent},
{path: 'dashboard', component: DashboardComponent},
{path: 'hero-details', component: HeroDetailComponent},
{path: '', redirectTo: 'dashboard'}
]
The behavior I encounter is a blank page whatever the address is.
If I change the last path, I experience something differently.
{path: '', redirectTo: 'dashboard', pathMatch: 'full'}
Now, even if I target a nonexisting route, I get redirected to the default path (and not redirected), and the index.html
is shown.
What's strange for me here is why the former one does not behave similarly. Why does it not redirect me to the index.html
?
Changing the last path to use pathMatch: 'prefix'
behaves even more unexpectedly.
{path: '', redirectTo: 'dashboard', pathMatch: 'prefix'}
Similarly, if I target a nonexisting address, I get redirected to the index.html
, even though everywhere is said that ''
prefixes everything, so shouldn't I be redirected to 'dashboard'
?
I would be extremely grateful if someone clears this concept up. Thanks!