# Dynamically mapUnknownRoutes in router-lite

**URL:** <https://discourse.aurelia.io/t/dynamically-mapunknownroutes-in-router-lite/5101>\
**Category:** vNext\
**Created:** [February 24, 2023, 12:48pm UTC](https://discourse.aurelia.io/t/dynamically-mapunknownroutes-in-router-lite/5101 "2023-02-24T12:48:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![elitastic](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/elitastic/32/1787_2.png) [@elitastic](https://discourse.aurelia.io/u/elitastic)\
**Post date:** [February 24, 2023, 12:48pm UTC](https://discourse.aurelia.io/t/dynamically-mapunknownroutes-in-router-lite/5101/1 "2023-02-24T12:48:03Z")

</div>

In Aurelia 1 it was possible to dynamically map an unknown route, e.g.:

```auto
config.mapUnknownRoutes(instruction =>
{
    const productId = instruction.parentInstruction.queryParams.productId;
    if (productId)
    {
        return { redirect: `detail/${encodeURIComponent(productId)}}` };
    }
    return { redirect: 'list' };
});

```

Is this somehow possible in Aurelia 2 with router-lite?

Thanks for any feedback.

---

<div class="post-metadata">

**Author:** ![Sayan751](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/sayan751/32/1861_2.png) [@Sayan751](https://discourse.aurelia.io/u/Sayan751)\
**Post date:** [February 24, 2023, 2:31pm UTC](https://discourse.aurelia.io/t/dynamically-mapunknownroutes-in-router-lite/5101/2 "2023-02-24T14:31:23Z")

</div>

Hi @elitastic! Thank you for reporting this. I can prioritize this in the coming days.

FYI, the `mapUnknownRoutes` is generally handled by the [`fallback` configuration option](https://docs.aurelia.io/router-lite/configuring-routes#fallback-redirecting-the-unknown-path). That lacks so far the function capability.

---

<div class="post-metadata">

**Author:** ![elitastic](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/elitastic/32/1787_2.png) [@elitastic](https://discourse.aurelia.io/u/elitastic)\
**Post date:** [February 24, 2023, 2:47pm UTC](https://discourse.aurelia.io/t/dynamically-mapunknownroutes-in-router-lite/5101/3 "2023-02-24T14:47:18Z")

</div>

Perfect, thank you for your help!

---

<div class="post-metadata">

**Author:** ![Sayan751](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/sayan751/32/1861_2.png) [@Sayan751](https://discourse.aurelia.io/u/Sayan751)\
**Post date:** [February 26, 2023, 9:41pm UTC](https://discourse.aurelia.io/t/dynamically-mapunknownroutes-in-router-lite/5101/4 "2023-02-26T21:41:33Z")

</div>

The feature is now available under the `dev` tag. For more info, refer the [PR](https://github.com/aurelia/aurelia/pull/1687).

The change in the docs follows.

---

<div class="post-metadata">

**Author:** ![Sayan751](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/sayan751/32/1861_2.png) [@Sayan751](https://discourse.aurelia.io/u/Sayan751)\
**Post date:** [February 27, 2023, 9:14pm UTC](https://discourse.aurelia.io/t/dynamically-mapunknownroutes-in-router-lite/5101/5 "2023-02-27T21:14:27Z")

</div>

The documentation changes are also now online: [https://docs.aurelia.io/router-lite/configuring-routes#fallback-redirecting-the-unknown-path](https://docs.aurelia.io/router-lite/configuring-routes#fallback-redirecting-the-unknown-path).

A toy example from the docs:

```typescript
import { customElement } from '@aurelia/runtime-html';
import {
  IRouteContext,
  ITypedNavigationInstruction_string,
  route,
  RouteNode,
  ViewportInstruction,
} from '@aurelia/router-lite';

@customElement({ name: 'ce-a', template: 'a' })
class A {}

@customElement({ name: 'n-f-1', template: 'nf1' })
class NF1 {}

@customElement({ name: 'n-f-2', template: 'nf2' })
class NF2 {}

@route({
  routes: [
    { id: 'r1', path: ['', 'a'], component: A },
    { id: 'r2', path: ['nf1'], component: NF1 },
    { id: 'r3', path: ['nf2'], component: NF2 },
  ],
  fallback(vi: ViewportInstruction, _rn: RouteNode, _ctx: IRouteContext): string {
    return (vi.component as ITypedNavigationInstruction_string).value === 'foo' 
      ? 'r2' 
      : 'r3';
  },
})
@customElement({
  name: 'my-app',
  template: `
  <nav>
  <a href="a">A</a>
  <a href="foo">Foo</a>
  <a href="bar">Bar</a>
</nav>

<au-viewport></au-viewport>`
})
export class MyApp {}

```
