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

Prefetch async route components #255

Merged
merged 11 commits into from
Sep 3, 2024
Merged

Prefetch async route components #255

merged 11 commits into from
Sep 3, 2024

Conversation

pleek91
Copy link
Contributor

@pleek91 pleek91 commented Sep 3, 2024

Description

Adds a new feature where if a route is defined with an async component (by using vue's defineAsyncComponent utility) that component will be prefetched into the app when a router-link to that route is mounted.

Copy link

netlify bot commented Sep 3, 2024

Deploy Preview for kitbag-router ready!

Name Link
🔨 Latest commit 119ddb4
🔍 Latest deploy log https://app.netlify.com/sites/kitbag-router/deploys/66d71097b806860008febf05
😎 Deploy Preview https://deploy-preview-255--kitbag-router.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Contributor

@stackoverfloweth stackoverfloweth left a comment

Choose a reason for hiding this comment

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

very clean solution, great feature 👏

Comment on lines +249 to +252
return new Promise(resolve => {
loaded = true
resolve({ default: { template: '' } })
})
Copy link
Contributor

Choose a reason for hiding this comment

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

clever!

const props = withDefaults(defineProps<RouterLinkProps & RouterPushOptions>(), {
// because prefetch can be a boolean vue automatically sets the default to false.
// Specifically setting the default to undefined
prefetch: undefined,
Copy link
Contributor

Choose a reason for hiding this comment

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

boo macros 👎

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In general I really like how vue defaults booleans to false. But it can cause some surprising errors when you're not really expecting it.

@pleek91 pleek91 merged commit f05e599 into main Sep 3, 2024
7 checks passed
@pleek91 pleek91 deleted the prefetch-components branch September 3, 2024 14:46
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