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

Already on GitHub? Sign in to your account

Adds support for async routes #13

Merged
merged 2 commits into from
Nov 2, 2016
Merged

Adds support for async routes #13

merged 2 commits into from
Nov 2, 2016

Conversation

PAkerstrand
Copy link
Collaborator

Adds support for async routes by not only taking "routes", but also the matched "components" into account. This allows us to lazily load routes using webpacks code-splitting feature while preserving support for get- and setProps.

if (route.components) {
const foundNamedComponent = Object.keys(route.components)
components.some((matchedComponent, i) => {
if (typeof matchedComponent === 'object') {
Copy link
Owner

Choose a reason for hiding this comment

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

We can probably use lodash.isplainobject here since we have it as a dependency already.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

👍

result.name = key;
matchedComponent = matchedComponent[key]; // eslint-disable-line no-param-reassign
Copy link
Owner

Choose a reason for hiding this comment

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

Are we sure that this mutation does not cause any problems? Seems like we are modifying renderProps indirectly here, no risk in doing so?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, it doesn't (it just changes the bound matchedComponent-parameter).
But might be a bit too clever. I'll re-write it to make the intent easier to read

@dlmr
Copy link
Owner

dlmr commented Nov 2, 2016

Looks good! We should probably add an example where we use async routes to verify that it also works in a "real" application.

@PAkerstrand PAkerstrand self-assigned this Nov 2, 2016
@PAkerstrand
Copy link
Collaborator Author

@dlmr Refactored findRouteByComponent to make intent clearer

@dlmr dlmr merged commit ee5e493 into master Nov 2, 2016
@dlmr dlmr deleted the support-async-routes branch November 2, 2016 20:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants