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

Run the loader on change of searchParams #54

Open
ashishworkspace opened this issue Apr 10, 2024 · 3 comments
Open

Run the loader on change of searchParams #54

ashishworkspace opened this issue Apr 10, 2024 · 3 comments

Comments

@ashishworkspace
Copy link

Hey, I just wanted to know if I can run the top-loading bar on every change in the search parameters.

@kapsule-studio
Copy link

Have you tried the shallowRouting options ?
https://github.com/Skyleen77/next-nprogress-bar?tab=readme-ov-file#shallowrouting-optional---boolean

@stefan-girlich
Copy link

stefan-girlich commented May 15, 2024

@kapsule-studio Unfortunately shallowRouting will not show the loading bar when only search params change.
Environment:

"next": "^14.2.3",
"nextjs-toploader": "^1.6.12",

Would you have any further ideas? Happy to provide debug information.

My current workaround

Invalidate route

    const applySearchParamsWorkaround = (url: URL): URL => {
        const { location } = window
        const isSamePage = url.pathname === location.pathname
        const paramsChanged = url.search !== location.search
        if (isSamePage && paramsChanged) {
            url.pathname = `force_reload_${Math.random()}`
        }

        return url
    }
  return (
    <ProgressBar
      shallowRouting
      targetPreprocessor={applySearchParamsWorkaround}
    />

Use custom useRouter

import { useRouter } from 'next-nprogress-bar'

@Glup3
Copy link

Glup3 commented Jun 30, 2024

Thanks for the workaround! @stefan-girlich

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

4 participants