aurelia / aurelia/framework

Lazy-loading feature when navigating to route

Open
#427 15 comments 3 reactions 0 assignees View on GitHub
enhancement
Dominant language
TypeScript
Stars
11.7k
Forks
608
PR merge metrics
No merged PRs in 30d

Description

This is something I first suggested in #376 - now as a separate issue :-)
Rob also commented about the possibility of making global resources be global only to a plugin/feature - I think that would fit very well into this.
##

Have you guys thought about how features and lazy-loaded routes might work together?
We're building a large site here, and it would be good for maintainability if each area of the site could be implemented as a feature, so e.g. any area-specific `globalResources` calls can be defined within the area, instead of in the site root - but the thing is, each of those areas are bundled separately, which means they are only loaded when the user actually navigates into the area. Would it be possible to support this?

I actually just tried putting this in the file containing the root component for an area, but it seems to break things - the `configure` function is actually invoked when I navigate into the area, but the `use` argument is undefined and afterwards the `Area1` class is never instantiated. If I remove the `configure` function, then the area loads as expected. No errors in the console though, so not sure what's going on... it may just be me trying to abuse things here, but I think it it could be handy if it worked :-) Thoughts?

``` typescript
import {FrameworkConfiguration} from "aurelia-framework";

export function configure(use: FrameworkConfiguration)
{
console.log("configure area"); // This is actually invoked when navigating into the area
}

export class Area1
{
constructor()
{
console.log("create area"); // This is only invoked if I remove the 'configure' function
}
}
```

Contributor guide

Open the contributing guide

Research direction

Start with the lazy-loaded area entry file shown in the issue, focusing on its configure function, FrameworkConfiguration argument, and Area1 entry point. Reproduce navigation with configure present and absent, then trace why the area is not instantiated. Done means lazy-loaded routes can configure area-specific global resources while the area still loads and Area1 is instantiated.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.