首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >辅助出口使整个页面按角度刷新。

辅助出口使整个页面按角度刷新。
EN

Stack Overflow用户
提问于 2022-05-13 04:31:22
回答 1查看 71关注 0票数 1

我在我的角度项目中使用辅助出口。

在我的routing.module.ts中有:

Routing.module.ts

代码语言:javascript
复制
    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:

代码语言:javascript
复制
<div id="main-content-container">
    <router-outlet></router-outlet>
</div>
<router-outlet name="secondary"></router-outlet>

在我的other.module文件中,我声明了以下路由:

Other.Module:

代码语言:javascript
复制
    {
    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,
        }]
}

现在,让我告诉您这是怎么回事:我正在尝试创建一个文件查看器库。这将从我的项目的几个点开始。所以我决定在我的项目中使用辅助路由。所以每当我想打开我的文件查看器时,我只想:

代码语言:javascript
复制
await this.router.navigate(['', {outlets: {secondary: 'other-file-viewer/image-viewer'}}]);

它会为我打开它。

我还将skipLocationChange: true传递给它,这样用户就不会注意到url的更改。还有一些queryParams。

代码语言:javascript
复制
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)

而且起作用了。当我点击按钮时,我的组件会打开。问题是,它也刷新了我在页面上已经拥有的内容。它基本上也是刷新我的主要出口。

我怎么才能避免这种情况?

如有任何建议,将不胜感激。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-05-16 08:30:39

不是角质问题。我把自己搞砸了。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72224473

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档