Попробуйте изменить первый маршрут
{
path: "",
redirectTo: "tabs",
pathMatch: "full"
}
и установите TabsModule
таким образом
const routes: Routes = [
{
path: "",
redirectTo: "default",
pathMatch: "full"
},
{
path: "default",
component: YourDefaultComponent
}
...
];
ОБНОВЛЕНИЕ: Если вы получаете ту же ошибку, выможно использовать AttachDetachReuseStrategy
import { ActivatedRouteSnapshot, RouteReuseStrategy, DetachedRouteHandle } from '@angular/router';
interface RouteStorageObject {
snapshot: ActivatedRouteSnapshot;
handle: DetachedRouteHandle;
}
export class CustomReuseStrategy implements RouteReuseStrategy {
handlers: { [key: string]: RouteStorageObject } = {};
retrieve(route: ActivatedRouteSnapshot): DetachedRouteHandle {
if (!route.routeConfig) return null;
if (route.routeConfig.loadChildren) return null;
return this.handlers[route.routeConfig.path];
}
.....
}
, затем я делаю shouldDetach
функцию, также проверяю loadChildren, чтобы предотвратить RouteReuseStrategy
сохранить неправильно ActivatedRouteSnapshot:
shouldDetach(route: ActivatedRouteSnapshot): boolean {
if (!route.routeConfig || route.routeConfig.loadChildren) {
return false;
}
return true;
}
Конечно, измените ваш AppModule
@NgModule({
imports: [...],
providers: [
{provide: RouteReuseStrategy, useClass: CustomReuseStrategy}
],
....
)}
export class AppModule {
}