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

Doesn't consider basePath? #78

Open
laggingreflex opened this issue Dec 14, 2021 · 3 comments
Open

Doesn't consider basePath? #78

laggingreflex opened this issue Dec 14, 2021 · 3 comments

Comments

@laggingreflex
Copy link

Does this not take basePath into consideration?

I have "/frontend" as my basePath and I'm seeing this in the logs (using redux-logger):

CHANGED: router.location.href /frontend/auth/login → /auth/login
CHANGED: router.location.pathname /frontend/auth/login → /auth/login

Not sure what the expected behaviour should be, but:

  • Should this route change even register, since they're basically the same paths?

  • Should "/frontend" either be added to, or omitted from both before-and after-states?

Great module BTW!

@laggingreflex
Copy link
Author

I can't reproduce it in the examples given, but it's definitely causing weird artifacts in my app. Like redundantly duplicating basePath "/frontend/frontend/...", and subsequently redirecting to it which obviously results in 404. I can't yet figure out why or where this is happening, or whether its my own app or this library...

But I've found a workaround that seems to avoid the issue of unnecessary redirection and path changes.

By patching next/router:

import Router from 'next/router'
import { createRouterMiddleware, ConnectedRouter } from 'connected-next-router';

/* Make `Router.asPath` return with `basePath` prefixed (if absent) */
const patchedRouter = new Proxy(Router, {
  get: (Router, key, receiver) => {
    if (key === 'asPath') {
      const { basePath, asPath } = Router
      const replaced = asPath.includes(basePath) ? asPath : basePath + asPath
      return replaced
    } else {
      return Reflect.get(Router, key, receiver)
    }
  }
})

createRouterMiddleware({ Router: patchedRouter })

<ConnectedRouter Router={patchedRouter}/>

@danielr18
Copy link
Owner

Hi @laggingreflex, I'm currently sick and can't investigate the issue at the moment. I should be able to next week.

@polaroidkidd
Copy link

polaroidkidd commented Mar 10, 2022

I'm also seeing this behavior, but only when using query parameters. Otherwise great work!

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

No branches or pull requests

3 participants