我在我的角度项目中使用辅助出口。
在我的routing.module.ts中有:
Routing.module.ts
const routes: Routes = [
{
path: '',
component: XXXComponet,
},
{
path: 'home',
component: YYYComponet,
},
{
path: 'file-viewer',
outlet: 'secondary',
loadChildren: () => import('../../other/app/other.app.module').then((m) => m.OtherAppModule),
},
{path: '**', canActivate: [AuthGuard], component: PageNotFoundComponent},我已经声明,对于路由(secondary:file-viewer),我希望装载我的other.module。在我的app.html中,我也有以下内容:
App.html:
<div id="main-content-container">
<router-outlet></router-outlet>
</div>
<router-outlet name="secondary"></router-outlet>在我的other.module文件中,我声明了以下路由:
Other.Module:
{
path: 'image-viewer',
component: ImageViewerComponent,
},
{
path: '',
component: AppComponent,
children: [
{
path: 'search',
component: AAAComponent,
children: [
{
path: 'result',
component: BBBViewComponent,
data: {needConnections: true},
},
{
path: '',
component: CCCViewComponent,
data: {needConnections: true},
},
],
},
{
path: 'explorer',
component: FFFViewComponent,
data: {needConnections: true},
},
{
path: 'reporter',
component: GGGViewComponent,
},
{
path: 'datasets',
component:KKKViewerComponent,
}]
}现在,让我告诉您这是怎么回事:我正在尝试创建一个文件查看器库。这将从我的项目的几个点开始。所以我决定在我的项目中使用辅助路由。所以每当我想打开我的文件查看器时,我只想:
await this.router.navigate(['', {outlets: {secondary: 'other-file-viewer/image-viewer'}}]);它会为我打开它。
我还将skipLocationChange: true传递给它,这样用户就不会注意到url的更改。还有一些queryParams。
await this.router.navigate(['', {outlets: {secondary: 'other-file-viewer/image-viewer'}}], {
skipLocationChange: true,
queryParams: {
id: params.fileId,
src: this.getDownloadStreamLink(params.fileId),
},
});因此,基本上当用户单击按钮时,url将从\xx\explorer更改为xx\explorer(secondary:file-viewer/image-viewer)。
而且起作用了。当我点击按钮时,我的组件会打开。问题是,它也刷新了我在页面上已经拥有的内容。它基本上也是刷新我的主要出口。
我怎么才能避免这种情况?
如有任何建议,将不胜感激。
发布于 2022-05-16 08:30:39
不是角质问题。我把自己搞砸了。
https://stackoverflow.com/questions/72224473
复制相似问题