Thorsten Westheider
Thorsten Westheider

Reputation: 10932

Pass parameters in Angular2 @RouteConfig redirectTo

Given a route config

@RouteConfig([
    new Route({ path: '/app/index.html', name: 'default', redirectTo: ['/View1] }),
    new Route({ path: '/view1/:param1/:param2/', name: 'View1', component: View1Component })
])

and param1, param2 being passed in as query parameters like so

http://legacy.com/app/index.html?param1=10&param2=15

how would I go about passing these parameters in the above redirectTo so that I'd end up with

http://legacy.com/app/#/view1/10/15

Is this possible to begin with?

Upvotes: 3

Views: 1831

Answers (1)

Günter Zöchbauer
Günter Zöchbauer

Reputation: 658017

This should work

@RouteConfig([
    new Route({ path: '/app', name: 'Default', redirectTo: ['/View1, {param1: 10, param2: 15}] }),
    new Route({ path: '/view1/:param1/:param2', name: 'View1', component: View1Component })
])

I modified the names an path a bit to make it compatible with the Angular2 style. If the /app/ really comes before index.html then there is something wrong in your configuration. See also Angular 2 router no base href set

Upvotes: 1

Related Questions