该问题可能是由于路由配置中缺少“ pathMatch: 'full'”属性所导致的。这个属性将确保路由只匹配完全匹配的URL而不是路由的一部分。
以下是一个具有“ pathMatch: 'full'”属性的示例路由配置:
const routes: Routes = [ { path: '', redirectTo: '/home', pathMatch: 'full' }, { path: 'home', component: HomeComponent }, { path: 'about', component: AboutComponent }, ];
在上面的例子中,“redirectTo”使用了“pathMatch: 'full'”以确保只有完全匹配“''”路径(空字符串)时才会重定向到“/home”。