Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Difference between lazy loaded routes and normal loaded routes #1593

Open
ivanbacher opened this issue Oct 6, 2022 · 3 comments
Open

Difference between lazy loaded routes and normal loaded routes #1593

ivanbacher opened this issue Oct 6, 2022 · 3 comments
Assignees

Comments

@ivanbacher
Copy link
Contributor

馃悰 Bug Report

Created a new app with a router + child router with the following routes:

main.ts

import Aurelia from 'aurelia';
import { RouterConfiguration } from '@aurelia/router';
import { MyApp } from './my-app';

Aurelia.register(RouterConfiguration.customize({ useUrlFragmentHash: true }))
  .app(MyApp)
  .start();

my-app.ts

import { HomePage } from './routes/home-page';

@routes([
  { path: '', redirectTo: 'home' },
  {
    path: 'home',
    component: () => HomePage01,
    title: 'Home',
  },
])

home-page.ts

import { ChildPage01 } from './child/child-page-01';

@routes([
  { path: '', redirectTo: 'child' },
  {
    path: 'child',
    component: ChildPage01,
    title: 'Child Page',
  },
])

So when the app opens in the browser for the first time the url is: /#/home/child.

However, if the routes are lazily loaded:

my-app.ts

@routes([
  { path: '', redirectTo: 'home' },
  {
    path: 'home',
    component: () => import('./routes/home-page'),
    title: 'Home',
  },
])

home-page.ts

@routes([
  { path: '', redirectTo: 'child' },
  {
    path: 'child',
    component: () => import('./child/child-page-01'),
    title: 'Child Page',
  },
])

The url is this /# when the app is loaded for the first time and the child route is not loaded.

Repro links:
Normal loaded routes: https://stackblitz.com/edit/au2-router-p1wmzl?file=src/routes/home-page.ts
Lazy loaded routes: https://stackblitz.com/edit/au2-router-gxy16b?file=src/routes/home-page.ts

@jwx
Copy link
Member

jwx commented Oct 6, 2022

This works in the latest release, please update.

@jwx jwx self-assigned this Oct 6, 2022
@ivanbacher
Copy link
Contributor Author

ivanbacher commented Oct 6, 2022

Super. I updated to 2.0.0-alpha.41 and it worked.

I noticed a different problem though. If I add in this to home-page.ts:

loading(params, instruction) {
    let p = new Promise((resolve, reject) => {
      setTimeout(() => {
        resolve(undefined);
      }, 1000);
    });
    return p;
  }

it doesn't work anymore. This is the case for both versions (normal loading and lazy loading). (I updated the stackblitz examples)

@bsrdjan
Copy link

bsrdjan commented Nov 10, 2022

works without redirectTo

path: ['', 'child'],

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants