2016-03-18 26 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,一切都沒有被重新加載。