Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

feat(pages)!: explicitly allow optional params with [[ #4537

Merged
merged 6 commits into from
Apr 26, 2022

Conversation

danielroe
Copy link
Member

@danielroe danielroe commented Apr 22, 2022

Resolves nuxt/nuxt#13408. Also see nuxt/nuxt#13788.

❓ 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

Currently routes ending in a dynamic param are marked as optional, e.g.: ~/pages/[slug].vue.

This PR instead requires double bracket syntax to enable optional params: e.g. ~/pages/[[slug]].vue. (This also means you can enable optional parameters earlier in the path.)

πŸ‘‰ Migration

If you are relying on [slug] at the end of a route to generate an optional parameter, you will need to rewrite it as [[slug]].

@danielroe danielroe added bug Something isn't working pages πŸ”¨ p3-minor-bug Priority 3: a bug in an edge case that only affects very specific usage labels Apr 22, 2022
@danielroe danielroe requested a review from atinux April 22, 2022 14:37
@danielroe danielroe self-assigned this Apr 22, 2022
@netlify
Copy link

netlify bot commented Apr 22, 2022

βœ… Deploy Preview for nuxt3-docs ready!

Name Link
πŸ”¨ Latest commit bbc3493
πŸ” Latest deploy log https://app.netlify.com/sites/nuxt3-docs/deploys/62680dfc4aaee0000827606a
😎 Deploy Preview https://deploy-preview-4537--nuxt3-docs.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 settings.

@pi0
Copy link
Member

pi0 commented Apr 22, 2022

This seems a good change but I guess it is not completely resolving nuxt/nuxt#13408 considering we might have more than one optional param in the path...

(Side note: Both server routes and vue-router does not have this consideration that "last dynamic segment is necessarily optional". i was unaware even we were doing this!)

@danielroe
Copy link
Member Author

@pi0 How about we change the default to non-optional at end of route, and use double brackets - e.g. [[slug]] - to indicate optionality, which can apply to any level in path?

@pi0
Copy link
Member

pi0 commented Apr 25, 2022

Double bracket seems a nice idea!

@danielroe danielroe added enhancement New feature or request and removed bug Something isn't working πŸ”¨ p3-minor-bug Priority 3: a bug in an edge case that only affects very specific usage labels Apr 25, 2022
@danielroe danielroe changed the title fix(pages): [slug]/index.vue param should be optional feat(pages)!: explicitly allow optional params with [[ Apr 25, 2022
@atinux
Copy link
Member

atinux commented Apr 25, 2022

I love this idea!

@atinux
Copy link
Member

atinux commented Apr 26, 2022

Happy to merge once the documentation is updated. Any blockers @pi0 ?

@pi0 pi0 merged commit 2bfd749 into main Apr 26, 2022
@pi0 pi0 deleted the fix/optional-router-params branch April 26, 2022 16:10
@pi0 pi0 mentioned this pull request May 2, 2022
@warflash warflash mentioned this pull request Jan 19, 2023
4 tasks
@danielroe danielroe added the 3.x label Jan 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
3.x enhancement New feature or request pages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support optional params in filename from ~/pages directory
3 participants