角度导航-导航到同级路线时无法删除queryParams

时间:2019-01-09 20:05:19

标签: angular angular-routing

我为我设置了这样的路线

        {
            path: 'events/:eventId/c/:customerId',
            component: CustomerEventComponent,
            children: [
                {
                    path: 'e',
                    component: CustomerExhibitorListComponent,
                },
                {
                    path: 'codes',
                    component: CustomerAccesscodeListComponent,
                },...
        }...

CustomerExhibitorListComponent和CustomerAccesscodeListComponent包含将某些状态存储为queryParams的数据网格,例如sort = NAME_ASC。

我使用的模板是

        <li>
            <a class="nav-link" routerLink="./e" routerLinkActive="active" [routerLinkActiveOptions]="{ exact: false }">{{ 'HOME.CUSTOMER_SIDENAV.EXHIBITOR_LIST' | translate }}</a>
        </li>
        <li>
            <a class="nav-link" routerLink="./codes" routerLinkActive="active" [routerLinkActiveOptions]="{ exact: false }">{{ 'HOME.CUSTOMER_SIDENAV.EXHIBITOR_ACCESSCODES' | translate }}</a>
        </li>

当我尝试在这两条路线之间切换时,将保留前一条路线的整个queryParams,并且无法重置它们。

我尝试使用queryParamsHandling并手动设置

[queryParms]="{sort:'...'}"

什么都行不通,只有当我转到另一条路线时,旧的queryparams才会消失。

最后,我已经订阅了父组件中的router.events并获得了一些有趣的日志

NavigationCancel
id: 3
reason: "Navigation ID 3 is not equal to the current navigation id 4"
url: "/home/o7kj72x5uix4ypk6/events/4d462c90-13f7-11e9-95fb-1b4b9f179c1a/c/b9eedf28-13f6-11e9-bb14-373ef19a0c85/e"


NavigationStart
id: 4
navigationTrigger: "imperative"
restoredState: null
url: "/home/o7kj72x5uix4ypk6/events/4d462c90-13f7-11e9-95fb-1b4b9f179c1a/c/b9eedf28-13f6-11e9-bb14-373ef19a0c85/e?offset=0&first=10&sort=NAME_ASC"

上一次导航之间的某个位置被取消(此处的路线似乎正确)。然后我又进行了第二次导航,从正确的目标网址开始

 /home/o7kj72x5uix4ypk6/events/4d462c90-13f7-11e9-95fb-1b4b9f179c1a/c/b9eedf28-13f6-11e9-bb14-373ef19a0c85/e

但是使用旧的Params

?offset=0&first=10&sort=NAME_ASC"

我没有设置任何Guards或Resolver。非常感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

我也遇到了这个问题,无法找到任何适当的方法来解决此问题,所以我有点黑了。就我而言,我使用的是Angular + Ionic,在Ionic中,我们有一个名为ionViewWillEnter的函数,每次视图渲染时都会调用该函数。所以我做了什么:

在函数ionViewWillEnter中,我只是重置了我的queryParams而不更改路由(请参见:Angular: How to update queryParams without changing route)。希望这对您的情况有所帮助。