Skip to content
This repository was archived by the owner on Apr 6, 2023. It is now read-only.
/frameworkPublic archive

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

Merged
pi0 merged 6 commits into
mainfrom
fix/optional-router-params
Apr 26, 2022
Merged

feat(pages)!: explicitly allow optional params with [[#4537
pi0 merged 6 commits into
mainfrom
fix/optional-router-params

Conversation

@danielroe

@danielroedanielroe commented Apr 22, 2022

Copy link
Copy Markdown
Member

Resolvesnuxt/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]].

@danielroedanielroe 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 atinuxApril 22, 2022 14:37
@danielroedanielroe self-assigned this Apr 22, 2022
@netlify

netlifyBot commented Apr 22, 2022

Copy link
Copy Markdown

Deploy Preview for nuxt3-docs ready!

NameLink
🔨 Latest commitbbc3493
🔍 Latest deploy loghttps://app.netlify.com/sites/nuxt3-docs/deploys/62680dfc4aaee0000827606a
😎 Deploy Previewhttps://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

pi0 commented Apr 22, 2022

Copy link
Copy Markdown
Member

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
Copy Markdown
MemberAuthor

@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

pi0 commented Apr 25, 2022

Copy link
Copy Markdown
Member

Double bracket seems a nice idea!

@danielroedanielroe 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
@danielroedanielroe changed the title fix(pages): [slug]/index.vue param should be optionalfeat(pages)!: explicitly allow optional params with [[Apr 25, 2022
@atinux

Copy link
Copy Markdown
Member

I love this idea!

@atinux

atinux commented Apr 26, 2022

Copy link
Copy Markdown
Member

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

pi0
pi0 approved these changes Apr 26, 2022
@pi0
pi0 merged commit 2bfd749 into mainApr 26, 2022
@pi0
pi0 deleted the fix/optional-router-params branch April 26, 2022 16:10
@pi0pi0 mentioned this pull request May 2, 2022
@warflashwarflash mentioned this pull request Jan 19, 2023
4 tasks
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

3.xenhancementNew feature or requestpages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support optional params in filename from ~/pages directory

3 participants

@danielroe@pi0@atinux