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

feat(nuxt): enable preloading object-syntax routes #19120

Merged

Conversation

Mini-ghost
Copy link
Contributor

πŸ”— Linked issue

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

After this PR, the path parsed by the following code all will be /home. As a result, the preload function will not retry and will instead return early.

<!-- Passing a string -->
<NuxtLink to="/home"> Home </NuxtLink>

<!-- Passing a string with query string -->
<!-- `router.resolve('/home?year=2023').path` is `/home` -->
<NuxtLink to="/home?year=2023"> Home </NuxtLink>

<!-- Passing a object -->
<!-- `router.resolve({ name: 'home', query: { year: '2023' } }).path` is `/home` -->
<NuxtLink :to="{ name: 'home', query: { year: '2023' } }"> Home </NuxtLink>

In addition, when users use preloadRouteComponents, they are not limited to type string.

const route: RouteLocationRaw = {
  name: 'dashboard'
}

preloadRouteComponents(dashboard)
const submit = async () => {
  const results = await $fetch('/api/authentication')
  if (results.token) {
    await navigateTo(dashboard)
  }
}

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@codesandbox
Copy link

codesandbox bot commented Feb 17, 2023

CodeSandbox logoCodeSandbox logoΒ  Open in CodeSandbox Web Editor | VS Code | VS Code Insiders

@danielroe
Copy link
Member

Would you update this following the merge of your other PR? πŸ™

# Conflicts:
#	packages/nuxt/src/app/components/nuxt-link.ts
@Mini-ghost
Copy link
Contributor Author

Mini-ghost commented Feb 21, 2023

Thank you for bringing this to my attention. I resolved the conflict caused by #19144.

@Mini-ghost
Copy link
Contributor Author

I'm unsure which option is better between using name or path for dynamic route, Even though they resolve to the same page components, their paths may still differ. While name may not have this issue, it is possible for it to be undefined or null.

Does the name of the route always exist in Nuxt? If so, would it be better to use it?

Overall, this issue is not significant because although dynamic routing repeats preloading, it doesn't require sending additional network requests.

@danielroe
Copy link
Member

name does not always exist, so I think better to use path.

@danielroe danielroe changed the title feat(nuxt): enable preloadRouteComponents to accept RouteLocationRaw values feat(nuxt): enable preloading object-syntax routes Mar 6, 2023
@danielroe danielroe merged commit ca32852 into nuxt:main Mar 6, 2023
@danielroe danielroe mentioned this pull request Mar 8, 2023
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