Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 273
Thorsten Westheider Avatar asked Jan 28 '26 15:01

Thorsten Westheider


1 Answers

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

like image 118
Günter Zöchbauer Avatar answered Jan 30 '26 05:01

Günter Zöchbauer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!