Skip to content

refactor routing logic #211

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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Dec 2, 2020
Merged

refactor routing logic #211

merged 15 commits into from
Dec 2, 2020

Conversation

Rich-Harris
Copy link
Member

This code was confusing the hell out of me. Still lots to do but this should be a lot friendlier. Essentially it adds two singletons, router and renderer — router selects routes given an href and interacts with the history API, while renderer is responsible for rendering a selected route (which includes loading its code and running preload).

};

branch = await Promise.all(
[[() => this.layout, () => {}], ...route.parts].map(async ([loader, get_params], i) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really get what this is doing. Why do we need a loader instead of just accessing this.layout directly? Why is get_params always returning {}?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need a loader instead of just accessing this.layout directly

because route.parts is an array of [loader, get_params] arrays, but the layout component is excluded from the manifest (because it's always present) so needs to be inserted before other components in a consistent way, and this was the quickest way to get it to behave


const { default: component, preload } = await loader();

const params = get_params ? get_params(match) : {};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we ever have to worry about get_params not being defined here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes. it's only included for page/layout components that have [dynamic] routes

@Rich-Harris Rich-Harris mentioned this pull request Dec 2, 2020
@Rich-Harris Rich-Harris changed the title [WIP] refactor routing logic refactor routing logic Dec 2, 2020
@Rich-Harris
Copy link
Member Author

A few minor TODOs remaining here and there but I think it makes sense to merge this for now

@Rich-Harris Rich-Harris merged commit 49f1ecf into master Dec 2, 2020
@Rich-Harris Rich-Harris deleted the router branch December 2, 2020 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants