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) –