首页 > 解决方案 > 使用查询参数 ionic 4 以编程方式导航页面

问题描述

我想将数据传递到另一个页面。我的 app-routing.module 是这样的:

const routes: Routes = [
  { path: '', redirectTo: 'home', pathMatch: 'full' },
  { path: 'home', loadChildren: './home/home.module#HomePageModule' },
  { path: 'web-page/:url', loadChildren: './web-page/web-page.module#WebPagePageModule' },
  { path: 'qrscan', loadChildren: './qrscan/qrscan.module#QrscanPageModule' },

];

使用 HTML 我可以成功传递数据:

   <ion-button expand="full" [routerLink]="['/web-page/', urlBooking]" routerDirection="forward">BOOKING</ion-button>

但我在打字稿中苦苦挣扎:

this.router.navigate(['web-page'], { queryParams: { 'url': "https://apple.stackexchange.com/questions/180387/xcode-failed-to-download-use-the-purchases-page-to-try-again" } });

标签: angularjsangular-routingionic4

解决方案


你没有说什么不起作用,但你可能想对你的查询参数进行 url 编码。这应该工作得很好。并decodeURIComponent在您使用该参数的地方使用。

const url = encodeURIComponent("https://apple.stackexchange.com/questions/180387/xcode-failed-to-download-use-the-purchases-page-to-try-again");
this.router.navigate(['web-page'], { queryParams: { url } });

推荐阅读