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

fix: localePath missing hash #78

Closed

Conversation

BobbieGoede
Copy link
Member

Description

Resolves nuxt-modules/i18n#2525

I believe the hash (as well as query) are being encoded twice (nuxt-modules/i18n#2523), will be looking into that.

Linked Issues

Additional context

@BobbieGoede BobbieGoede reopened this Oct 27, 2023
@@ -104,13 +105,14 @@ export function resolveBridgeRoute(val: BridgeRoute) {
export function resolvedRouteToObject(route: BridgeRoute): BridgeRoute {
const r = resolveBridgeRoute(route)

const { search, hash } = parsePath(r.fullPath)

const encodedPath = encodeURI(r.path)

Choose a reason for hiding this comment

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

Just while we're at it: This line encodes a properly encoded route twice for me, using useSwitchLocalePath. Could encodeURI be removed here or be called under different circumstances?

The callstack goes like this:

  • useSwitchLocalePath
  • _useSwitchLocalePath
  • switchLocalePath
  • localePath
  • resolveRoute
  • resolvedRouteToObject ... where the route`s path is already urlencoded and will be erroneously encoded a second time here

Nuxt 3.8, @nuxtjs/i18n npm:@nuxtjs/i18n-edge@8.0.0-rc.5-28305512.c5b00d5

Any quick ideas?

Copy link
Member Author

Choose a reason for hiding this comment

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

The encoding should probably moved someplace else or be handled differently, the issue of double encoding started after #76, but without that change users experienced lack of encoding some of the time.

I've been looking into vuejs/router as to when and where encoding happens, encodeURI is hardly used there or its usage is at least modified, see encoding.ts. The there comments refer to some cross-browser differences in encoding as well, maybe this could be why some users seem to experience encoding issues more than others?

This PR only fixes missing hash in URLs (only happens for URLs without search/query parameters), the encoding issue is a bit more complicated 😅 so will likely be a separate PR. Might end up copying some of the router code as is, as not all of it is exported, or perhaps we can make better use of the routers functions earlier in the code.

Choose a reason for hiding this comment

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

Ah, I think there is already a ticket for what I described: nuxt-modules/i18n#2523

@kazupon
Copy link
Member

kazupon commented Nov 4, 2023

close, since we have merged #79

@kazupon kazupon closed this Nov 4, 2023
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.

Hash in NuxtLink don't work with LocalePath
3 participants