2016-03-18 23 views
0

URL参数是有一些如何使用代码来添加一个新的URL参数,例如:角2 - 增加需求

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 
} 
+1

的可能的复制[变更路径PARAMS而不在角度2重装](http://stackoverflow.com/questions/35618463/change-route-params-without-reloading-in-angular-2) –

回答

1

你可以使用Angulars Location。通过这种方式只有url被更新,但路由器没有导航到它。

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

TY ,达斯库斯! tyvm! –

0

如果实现CanReuse并返回true可以renavigate将添加的参数的URL,一切都没有被重新加载。