首页 > 解决方案 > 如何在 ionic 3 中更改时获取 url 参数?

问题描述

我正在我的应用页面上加载 URL。在那,如果点击提交后URL参数会发生变化 - 如何获取URL中参数的变化?

updateUrl() {
   console.log('check');
   let localaccesstoken = localStorage.getItem('token');
   let Url = 'http://abcd.net/outfit/index.php?option=com_j2store&view=checkout&mobile=mobile&tmpl=component';
   let checkoutPage = window.open(Url, '_self');
   console.log(JSON.stringify(checkoutPage));
   return this.sanitizer.bypassSecurityTrustResourceUrl(Url);
}

上面的函数会丢失 URL。

如果发生任何更改,请帮助我捕获 URL。

标签: jquerytypescriptionic-frameworkwebviewionic3

解决方案


在 Angular 中,我们可以订阅(Rx 事件)到路由器实例

class MyClass {
  constructor(private router: Router) {
    router.events.subscribe((val) => {
        // see also 
        console.log(val instanceof NavigationEnd) 
    });
  }
}

或者

this.router.events.subscribe(event: Event => {
    // Handle route change
});

推荐阅读