【问题标题】:Angular 2 - add URL parameter on demandAngular 2 - 按需添加 URL 参数
【发布时间】:2016-07-05 02:05:47
【问题描述】:

是否有一些如何使用代码添加新的 URL 参数,例如:

http://example.com/mypage?par=1&par2=2

我的代码中需要类似:

if (myVar == 'abc') { 
    // add a par3=3 without navigate/refresh the page - just to 
    // add a decoration on the URL for bookmarks purposes, 
    // for example: when user bookmark it and go back, 
    //I will be displaying the same dialog box 
}

【问题讨论】:

标签: angular angular2-routing


【解决方案1】:

如果您实现 CanReuse 并返回 true,您可以使用添加的参数重新导航到 URL,而无需重新加载所有内容。

【讨论】:

    【解决方案2】:

    您可以使用 Angulars Location。这样只会更新 url,但路由器不会导航到它。

    import {Location} from 'angular2/router';
     class Component {
      constructor(location: Location) {
        location.go('/foo');//Add your params here
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-30
      • 1970-01-01
      • 2016-05-04
      • 1970-01-01
      • 2017-02-12
      • 1970-01-01
      • 1970-01-01
      • 2020-12-25
      相关资源
      最近更新 更多