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

fix(nuxt): normalise window location for universal router - #4841

Merged
pi0 merged 4 commits into
mainfrom
fix/universal-path
May 6, 2022
Merged

fix(nuxt): normalise window location for universal router#4841
pi0 merged 4 commits into
mainfrom
fix/universal-path

Conversation

@danielroe

Copy link
Copy Markdown
Member

🔗 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

currently route.fullPath is / on server and http://localhost:3000/ on client. This implements same behaviour as on router, which also fixes an issue where baseURL wasn't being correctly handled with universal router:

// https://github.dev/vuejs/router/blob/main/src/history/html5.ts#L33-L56
functioncreateCurrentLocation(
base: string,
location: Location
): string{
const{ pathname, search, hash }=location
// allows hash bases like #, /#, #/, #!, #!/, /#!/, or even /folder#end
consthashPos=base.indexOf('#')
if(hashPos>-1){
constslicePos=hash.includes(base.slice(hashPos))
? base.slice(hashPos).length
: 1
letpathFromHash=hash.slice(slicePos)
// prepend the starting slash to hash so the url starts with /#
if(pathFromHash[0]!=='/'){pathFromHash='/'+pathFromHash}
returnwithoutBase(pathFromHash,'')
}
constpath=withoutBase(pathname,base)
returnpath+search+hash
}

📝 Checklist

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

@danielroedanielroe added bug Something isn't working 🔨 p3-minor-bug Priority 3: a bug in an edge case that only affects very specific usage labels May 6, 2022
@danielroe
danielroe requested a review from pi0May 6, 2022 10:13
@danielroedanielroe self-assigned this May 6, 2022
@netlify

netlifyBot commented May 6, 2022

Copy link
Copy Markdown

Deploy Preview for nuxt3-docs canceled.

NameLink
🔨 Latest commit8a4fe13
🔍 Latest deploy loghttps://app.netlify.com/sites/nuxt3-docs/deploys/6274ff59541368000919cf26

Comment threadpackages/nuxt/src/app/plugins/router.ts Outdated
Comment threadpackages/nuxt/src/app/plugins/router.ts Outdated
pi0
pi0 approved these changes May 6, 2022
@pi0
pi0 merged commit b29f635 into mainMay 6, 2022
@pi0
pi0 deleted the fix/universal-path branch May 6, 2022 11:02
@pi0pi0 mentioned this pull request May 6, 2022
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

3.xbugSomething isn't working🔨 p3-minor-bugPriority 3: a bug in an edge case that only affects very specific usage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@danielroe@pi0