简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM