5
我的web應用程序有多個過濾器,應該在當前Url中表示,以便用戶可以簡單地複製/書籤當前頁面以便稍後返回。
在angular1中,我使用$location.search(name, value)
來簡單地設置改變時的參數參數。現在我想在angular2中獲得類似的東西。
還是錯了?
我的web應用程序有多個過濾器,應該在當前Url中表示,以便用戶可以簡單地複製/書籤當前頁面以便稍後返回。
在angular1中,我使用$location.search(name, value)
來簡單地設置改變時的參數參數。現在我想在angular2中獲得類似的東西。
還是錯了?
我認爲你必須使用Angular2內部的路由器。代碼示例:
import {Component} from 'angular2/core';
import {RouteConfig, ROUTER_DIRECTIVES} from 'angular2/router';
import {ProfileComponent} from './profile.component';
@Component({
selector: 'my-app',
template: `
<router-outlet></router-outlet>
`,
directives: [ROUTER_DIRECTIVES]
})
@RouteConfig([
{path: '/profile/:id', name: 'Profile', component: ProfileComponent}
])
export class AppComponent {
}
的:ID是一個路由參數,你可以做這樣的一個網址: /型材/ 2和2是id參數的值。
你可以找到在Angular2文檔更詳細:router doc
謝謝你,但是如果我有多個可選參數是什麼? –
在這種情況下,你必須使用queryParams,並且StackOverflow上有一個鏈接:[route optional parameters](http://stackoverflow.com/questions/34208745/angular-2-optional-route-parameter) –