# canLoad redirect with @aurelia/router

**URL:** <https://discourse.aurelia.io/t/canload-redirect-with-aurelia-router/4786>\
**Category:** vNext\
**Created:** [May 26, 2022, 1:01pm UTC](https://discourse.aurelia.io/t/canload-redirect-with-aurelia-router/4786 "2022-05-26T13:01:27Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ivan](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/ivan/32/2022_2.png) [@ivan](https://discourse.aurelia.io/u/ivan)\
**Post date:** [May 26, 2022, 1:01pm UTC](https://discourse.aurelia.io/t/canload-redirect-with-aurelia-router/4786/1 "2022-05-26T13:01:27Z")

</div>

I am using `@aurelia/router` instead of `router-lite` and would like to redirect a user to the “home page” if a certain condition is met.

`main.js`

```auto
import { RouterConfiguration } from '@aurelia/router'

Aurelia
  .register(RouterConfiguration.customize({
    useDirectRouting: false,
    useUrlFragmentHash: true,
    useHref: false
  }))

```

Im `my-app.js` I specify the routes.

```auto
import { IRouter, routes } from '@aurelia/router'

@routes( [
  { path: '', redirectTo: 'step-01' },

  { id: 'step-01', path: 'step-01', component: import('...')},
  { id: 'step-02', path: 'step-02', component: import('...') }
])

```

In `step-02.js` I am using the `canLoad` hook.

```auto
canLoad() {
    if (something) {
      return 'step-01'
    } else {
      return true
    }
  }

```

This gives an error:

Uncaught (in promise) Error: `'step-01'` did not match any configured route or registered component name - did you forget to add the component ‘step-01’ to the dependencies or to register it as a global dependency?

What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![manks](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/manks/32/1995_2.png) [@manks](https://discourse.aurelia.io/u/manks)\
**Post date:** [May 27, 2022, 12:48am UTC](https://discourse.aurelia.io/t/canload-redirect-with-aurelia-router/4786/2 "2022-05-27T00:48:47Z")

</div>

Is `step-01` a root path? What happens if you specify `/step-01`?

---

<div class="post-metadata">

**Author:** ![ivan](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/ivan/32/2022_2.png) [@ivan](https://discourse.aurelia.io/u/ivan)\
**Post date:** [May 27, 2022, 6:07am UTC](https://discourse.aurelia.io/t/canload-redirect-with-aurelia-router/4786/3 "2022-05-27T06:07:18Z")

</div>

Should be. Still get the same error:

```auto
Error: '/step-01' did not match any configured route or registered component name

```

```auto
Error: '#/step-01' did not match any configured route or registered component name

```

---

<div class="post-metadata">

**Author:** ![sarp](https://avatars.discourse-cdn.com/v4/letter/s/ad7895/32.png) [@sarp](https://discourse.aurelia.io/u/sarp)\
**Post date:** [July 13, 2022, 9:20pm UTC](https://discourse.aurelia.io/t/canload-redirect-with-aurelia-router/4786/4 "2022-07-13T21:20:19Z")

</div>

I am having the exact same problem. As a part of upgrading to alpha v33, I tried to switch from router-lite to @aurelia/router, but had to undo for the moment. Did you get any progress regarding this since last message?

---

<div class="post-metadata">

**Author:** ![ivan](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/ivan/32/2022_2.png) [@ivan](https://discourse.aurelia.io/u/ivan)\
**Post date:** [July 14, 2022, 4:31am UTC](https://discourse.aurelia.io/t/canload-redirect-with-aurelia-router/4786/5 "2022-07-14T04:31:46Z")

</div>

No, unfortunately not.

---

<div class="post-metadata">

**Author:** ![sarp](https://avatars.discourse-cdn.com/v4/letter/s/ad7895/32.png) [@sarp](https://discourse.aurelia.io/u/sarp)\
**Post date:** [September 23, 2022, 7:53pm UTC](https://discourse.aurelia.io/t/canload-redirect-with-aurelia-router/4786/6 "2022-09-23T19:53:54Z")

</div>

Hey @Ivan. Did you have any progress on this? If not, I somewhat had progress with this issue and might be able to help.

---

<div class="post-metadata">

**Author:** ![ivan](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/ivan/32/2022_2.png) [@ivan](https://discourse.aurelia.io/u/ivan)\
**Post date:** [September 24, 2022, 8:38am UTC](https://discourse.aurelia.io/t/canload-redirect-with-aurelia-router/4786/7 "2022-09-24T08:38:24Z")

</div>

I took a different approach. Please do share, curios to see your solution.

---

<div class="post-metadata">

**Author:** ![dwaynecharrington](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/dwaynecharrington/32/11_2.png) [@dwaynecharrington](https://discourse.aurelia.io/u/dwaynecharrington)\
**Post date:** [October 5, 2022, 5:12am UTC](https://discourse.aurelia.io/t/canload-redirect-with-aurelia-router/4786/8 "2022-10-05T05:12:08Z")

</div>

This should work in the latest version of the router. You can now direct by providing a route name amongst other values.

---

<div class="post-metadata">

**Author:** ![sarp](https://avatars.discourse-cdn.com/v4/letter/s/ad7895/32.png) [@sarp](https://discourse.aurelia.io/u/sarp)\
**Post date:** [November 3, 2022, 4:52pm UTC](https://discourse.aurelia.io/t/canload-redirect-with-aurelia-router/4786/9 "2022-11-03T16:52:00Z")

</div>

In my case, it was not working as in yours. So I reverted the upgrade and later upgraded to alpha41. The there, I fixed the problem by making sure all imports are coming from the same library. There was a mix up between used libraries basically. But also @dwaynecharrington points out that it should be working in the latest version anyway. So now, I am not as sure as I was when I prompted you that I might have a solution, whether if it was the inconsistent imports, a generic problem in the framework that got fixed in later alpha versions, or both 😃

I’m sorry 😅
