# Route parameters, determineActivationStrategy and configureRouter in Aurelia 2?

**URL:** <https://discourse.aurelia.io/t/route-parameters-determineactivationstrategy-and-configurerouter-in-aurelia-2/4305>\
**Category:** vNext\
**Created:** [July 5, 2021, 2:39pm UTC](https://discourse.aurelia.io/t/route-parameters-determineactivationstrategy-and-configurerouter-in-aurelia-2/4305 "2021-07-05T14:39:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![deap82](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/deap82/32/203_2.png) [@deap82](https://discourse.aurelia.io/u/deap82)\
**Post date:** [July 5, 2021, 2:39pm UTC](https://discourse.aurelia.io/t/route-parameters-determineactivationstrategy-and-configurerouter-in-aurelia-2/4305/1 "2021-07-05T14:39:53Z")

</div>

I’ve been looking at the documentation of Routing in Aurelia 2 and also found this migration guide;  
[https://docs.aurelia.io/resources/cheat-sheet#migrating-from-v1-3](https://docs.aurelia.io/resources/cheat-sheet#migrating-from-v1-3)

However, nowhere are route parameters mentioned. In my current app I just have a few route “patterns” set up with parameters annotated with colon, for example  
`route: ':controller/:action/:id?/'`

In Aurelia 1 the colons means that there are three parameters; controller, action and id. And the question mark means that id is optional.

Is this possible to use in the new “path” property of Aurelia 2 routes?

* * *

Also, the migration docs does not mention anything about how to migrate the `determineActivationStrategy` method that exists in Aurelia 1.

* * *

Lastly, my current `configureRouter` method depends on some data that I’m injecting to my app class.  
But now when the route configuration is to be done through a decorator on the App class, does it mean that all data for the routing must be constant or could I somehow call a method and build up my routes array using logic as I can in configureRouter of Aurelia 1?

```auto
@route({ routes: MyApp.buildRouteArray() })
export class MyApp {
    public static buildRouteArray() { 
      let data = aurelia.container.get(MyAppDataModel); //get my data object from DI container
     /.../ //build route array
   }
}

```

Any input on whether this or something like it will possible or not would be much appreciated.

---

<div class="post-metadata">

**Author:** ![fkleuver](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/fkleuver/32/994_2.png) [@fkleuver](https://discourse.aurelia.io/u/fkleuver)\
**Post date:** [July 6, 2021, 6:15pm UTC](https://discourse.aurelia.io/t/route-parameters-determineactivationstrategy-and-configurerouter-in-aurelia-2/4305/2 "2021-07-06T18:15:30Z")

</div>

> [@deap82](#):
>
> Is this possible to use in the new “path” property of Aurelia 2 routes?

Yes the syntax for `path` in v2 supports all the v1 stuff too.

> [@deap82](#):
>
> Also, the migration docs does not mention anything about how to migrate the `determineActivationStrategy` method that exists in Aurelia 1.

That’s renamed to `transitionPlan` which can be `'replace'`, `'invoke-lifecycles'` or `'none'`, or a function returning one of those values. This is a property of the route config you pass into the decorator.

> [@deap82](#):
>
> or could I somehow call a method and build up my routes array using logic as I can in configureRouter of Aurelia 1?

You could inject `IRouteContext` as a dependency in your component and then call `.addRoute` to add additional routes in the constructor. That route context is also where the static route config (that you added via the decorator or `static routes`) ends up. It’s the main entry point for component-scoped routing stuff (like child routers used to be in v1)

---

<div class="post-metadata">

**Author:** ![deap82](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/deap82/32/203_2.png) [@deap82](https://discourse.aurelia.io/u/deap82)\
**Post date:** [July 12, 2021, 9:53am UTC](https://discourse.aurelia.io/t/route-parameters-determineactivationstrategy-and-configurerouter-in-aurelia-2/4305/3 "2021-07-12T09:53:36Z")

</div>

@fkleuver,

When I try to inject `IRouteContext` I get an error:  
`Error: Attempted to jitRegister an interface: IRouteContext`

Just by chance I tried to inject `RouteContext` instead, but it also gives error:  
`TypeError: Cannot read property 'root' of undefined (at new RouteContext, route-context.ts:131)`

Perhaps I should add that I’m trying to this in the constructor of my root component (the one passed to the `app` method of the Aurelia instance) and not to have any routes registered with the `@route` decorator at all.

---

<div class="post-metadata">

**Author:** ![fkleuver](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/fkleuver/32/994_2.png) [@fkleuver](https://discourse.aurelia.io/u/fkleuver)\
**Post date:** [July 12, 2021, 4:05pm UTC](https://discourse.aurelia.io/t/route-parameters-determineactivationstrategy-and-configurerouter-in-aurelia-2/4305/4 "2021-07-12T16:05:26Z")

</div>

You only need `IRouteContext` when you need to _append_ routes to a component that already has routes. Since you don’t, you can just call the static `Route.configure` api like so:

```auto
Route.configure({
  routes: [
    { path: '', component: import('./home'), title: 'Home' }
  ]
}, App);

```

Which is functionally equivalent to doing this (these are just 2 different entry points to the same api):

```auto
@route({
  routes: [
    { path: '', component: import('./home'), title: 'Home' }
  ]
})
export class App {}

```

For future readers who do need the `IRouteContext` in the app root: a workaround is to retrieve it in the `created` hook, e.g.:

```auto
export class App {
  created(controller) {
    const routeContext = controller.context.get(IRouteContext);
  }
}

```

This workaround only applies to the app root and might be lifted in a future release, it’s due to a circular dependency that still needs to be addressed.
