3

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?

Thorsten Westheider
  • 10,572
  • 14
  • 55
  • 97
  • I think angular should add this as a feature, all full redirects should automatically carry forward params and query params... it's how servers do it too – Ayyash May 05 '17 at 07:36

1 Answers1

1

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

Community
  • 1
  • 1
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
  • Yeah, I noticed. However, `param1` and `param2` are not fixed, that's just the problem. If they're passed to a component I can grab them from `routeParams` but there's no way to get their runtime values inside the route config, is there? – Thorsten Westheider Apr 18 '16 at 08:30
  • 1
    No, what you can do is to redirect to a helper component and there redirect imperatively and passing runtime values. `constructor(router:Router) { router.navigateXxx(...); }`. Actually you would change your `redirectTo:` to `component: SomeHelperComponent` and in this component you do the imperative redirection. – Günter Zöchbauer Apr 18 '16 at 08:34