在Angular应用程序(v4.3.6)中,我有一个搜索页面,其中搜索参数保存在URL中 . 例如: https://mysite/#/search?q=queryText&page=3

要求是用户可以将填充了搜索参数的URL传递给其他用户以共享相同的搜索结果 . 一切正常,除非刷新页面,因为在这种情况下,所有查询参数(存在于URL中)都会被忽略,因此在页面加载后会丢失 .

我们的路由文件:

const routes: Routes = [
{ path: "", redirectTo: "/home", pathMatch: "full" },
{ path: "home", component: HomeComponent },
{ path: "search", component: SearchComponent },
{ path: "404", component: NotFoundComponent },
{ path: "**", redirectTo: "/404" },
];

使用新queryParams更新URL的服务文件:

public updateUrl(state) {

    // Here logic to transform state into proper queryParams format

    this.router.navigate(["/search"], {
       queryParams: params,
       queryParamsHandling: "merge",
       replaceUrl: true,
    });
}

在页面刷新时,Angular仅保留routeParams但不保留queryParams(即使它们在URL中可用) .

是否可以通过适当的设置将它们保留在页面刷新上,或者唯一的方法是在本地保留它们并恢复它们?