Javascript 角2+中的角粘性状态;
我正在将Angular 1.5.X应用程序迁移到Angular 4。 在我的应用程序中,当我在应用程序的某些视图中进行导航时,我使用Angular Ui Router Stick State以避免丢失视图内容,但当我尝试在ng-router2中使用此功能时,我找不到它Javascript 角2+中的角粘性状态;,javascript,angularjs,angular,angular-ui-router,angular2-routing,Javascript,Angularjs,Angular,Angular Ui Router,Angular2 Routing,我正在将Angular 1.5.X应用程序迁移到Angular 4。 在我的应用程序中,当我在应用程序的某些视图中进行导航时,我使用Angular Ui Router Stick State以避免丢失视图内容,但当我尝试在ng-router2中使用此功能时,我找不到它 有人知道Angular2+中的某个路由器具有与粘性状态类似的功能,或者使用ui-router-ng2模拟粘性状态。我在互联网上找到了这个答案,我记不起网络了,但解决方案不是我的 import { Injectable } from
有人知道Angular2+中的某个路由器具有与粘性状态类似的功能,或者使用ui-router-ng2模拟粘性状态。我在互联网上找到了这个答案,我记不起网络了,但解决方案不是我的
import { Injectable } from '@angular/core';
import { Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, RouteReuseStrategy, DetachedRouteHandle, Route} from '@angular/router';
@Injectable()
export class ArchReuseStrategyService implements RouteReuseStrategy {
handlers: {[key: string]: DetachedRouteHandle} = {};
/** Determine if should detach the route */
shouldDetach(route: ActivatedRouteSnapshot): boolean {
console.log('CustomReuseStrategy:shouldDetach', route);
return (route.routeConfig.sticky === true) ? true : false;
// Or return true;
}
/** Store the route */
store(route: ActivatedRouteSnapshot, handle: DetachedRouteHandle): void {
console.log('CustomReuseStrategy:store', route, handle);
this.handlers[route.routeConfig.path] = handle;
}
/** Determina si la ruta y su subrutas deberian poder ser recuperadas */
shouldAttach(route: ActivatedRouteSnapshot): boolean {
console.log('CustomReuseStrategy:shouldAttach', route);
return !!route.routeConfig && !!this.handlers[route.routeConfig.path];
}
/** Recover a store route*/
retrieve(route: ActivatedRouteSnapshot): DetachedRouteHandle {
console.log('CustomReuseStrategy:retrieve', route);
if (!route.routeConfig) return null;
return this.handlers[route.routeConfig.path];
}
/** Determine if the route should be reused*/
shouldReuseRoute(future: ActivatedRouteSnapshot, curr: ActivatedRouteSnapshot): boolean {
console.log('CustomReuseStrategy:shouldReuseRoute', future, curr);
return future.routeConfig === curr.routeConfig;
}
}
我也有同样的问题-一个带有子组件(选项卡)的父组件,这些子组件的视图可以包含各种iFrame/对象,我希望避免每次用户在子组件之间切换时重新加载这些iFrame/对象。