我有一个具有以下嵌套组件结构的AngularDart 5应用程序:
带有主路由器插座的mainComponent
。其路径为/
。
组件A
作为mainComponent
的子元素。它也有自己的路由器出口,路径为/a
。
组件1
作为A
的子代。其路径为/a/1
。
组件2
作为A
的另一个子元素。它的路径是
/a/2
。
从1
切换到2
会触发页面a
的重新加载/呈现吗?
例如在a
中播放视频时,是否会从1
切换到2
以便重新加载视频?
如果是这样,可以预防吗?
我实际上是在问这个问题,因为对我来说,从1
切换到2
时,页面将重新加载/呈现。
编辑:
这是我的路由配置。
主要组件的路线:
class AppRoutePaths {
static final portal = RoutePath(path: 'portal');
static final workspace = RoutePath(path: 'workspace');
}
class AppRoutes {
static final _default = RouteDefinition.redirect(
path: '', redirectTo: AppRoutePaths.portal.toUrl());
static final _workspaceRoute = RouteDefinition(
routePath: AppRoutePaths.workspace,
component:
workspace_component.WorkspaceComponentNgFactory as ComponentFactory);
static final all = [_default, _workspaceRoute];
}
和相应的路由器出口:
<router-outlet [routes]="AppRoutes.all"></router-outlet>
这些是组件A
的路由:
class WorkspaceRoutePaths {
static final dashboard =
RoutePath(path: 'dashboard', parent: AppRoutePaths.workspace);
static final settings =
RoutePath(path: 'settings', parent: AppRoutePaths.workspace);
}
class WorkspaceRoutes {
static final dashboard = RouteDefinition(
routePath: WorkspaceRoutePaths.dashboard,
component: dashboard_component_template.DashboardComponentNgFactory as ComponentFactory);
static final settings = RouteDefinition(
routePath: WorkspaceRoutePaths.settings,
component: settings_component_template.SettingsComponentNgFactory as ComponentFactory);
static final _default = RouteDefinition.redirect(
path: '', redirectTo: WorkspaceRoutePaths.dashboard.toUrl());
static final all = [dashboard, settings, _default];
}
和相应的路由器出口:
<router-outlet [routes]="WorkspaceRoutes.all"></router-outlet>
答案 0 :(得分:0)
如果要重用组件,则需要在组件中添加CanReuse
mixin。
对于组件A
,它看起来像这样:
@Component(
selector: "component-a",
templateUrl: "component-a.html",
styleUrls: ["component-a.css"],
directives: [routerDirectives])
class A with CanReuse {...}