Refactor: rebuild file-based route config to be more static

This issue has been tracked since 2023-01-31.

Which scope/s are relevant/related to the feature request?

router

Information

Currently, to build the route config, we parse the files and create a tree of lazy loaded routes using loadChildren at the leaf nodes to build the route config dynamically at runtime.

The produced result looks like this for /src/app/routes/about.ts

[
  {
    path: 'about',
    loadChildren: () => import('./src/app/routes/about').then(m => [
      {
        component: m.default,
        ...m.routeMeta
      }
  }
]

To make this more static, we could parse the files, but create static imports for only the routeMeta, and lazy load the component

import { routeMeta as routeMeta_0_0 } from '/src/app/routes/about';

[
  {
    path: 'about',
    loadComponent: () => import('/src/app/routes/about'),
    ...routeMeta_0_0
  }
]

Parent/Child routes

import { routeMeta as routeMeta_0_0 } from '/src/app/routes/parent';
import { routeMeta as routeMeta_1_0 } from '/src/app/routes/parent/child';

[
  {
    path: 'parent',
    loadComponent: () => import('/src/app/routes/parent'),
    children: [
      {
         path: 'child',
        loadComponent: () => import('/src/app/routes/parent/child'),
        ...routeMeta_1_0
      }
    ]
  }
]

Each file might require a routeMeta export but that's TBD

Describe any alternatives/workarounds you're currently using

No response

I would be willing to submit a PR to fix this issue

  • Yes
  • No
More Details About Repo
Owner Name analogjs
Repo Name analog
Full Name analogjs/analog
Language TypeScript
Created Date 2022-07-06
Updated Date 2023-03-28
Star Count 885
Watcher Count 18
Fork Count 67
Issue Count 33

YOU MAY BE INTERESTED

Issue Title Created Date Updated Date