FireGM FireGM - 1 month ago 117x
TypeScript Question

How get query params from url in angular2?

I use angular2.0.0-beta.7. When component is loaded on path like "/path?query=value1" it's redirect to "/path". Why GET params was deleted? How preserve params?

error in routers. If i have main route like

path: '/todos/...',
name: 'TodoMain',
component: TodoMainComponent

and my child route like

{ path: '/', component: TodoListComponent, name: 'TodoList', useAsDefault:true },
{path: '/:id', component: TodoDetailComponent, name:'TodoDetail'}

i cant get params in TodoListComponent.
Now i can get matrix params("/my/path;param1=value1;param2=value2"), but i want classic query params("/my/path?param1=value1&param2=value2")


First off, what I have found working with Angular2 is that the url with a query string would be /path;query=value1

To access it in a component you use So is this, but now follows a code block:

    constructor(params: RouteParams){
    var val = params.get("query");

As to why it would be removed when you load the component, that isn't default behavior. I checked specificly in a clean test project and wasn't redirected or changed. Is it a default route or something else that is special about the routing?

Read about routing with query strings and params in the Angular2 Tutorial at!#query-parameters