Replies: 2 comments
|
I don't that can be handled by the package itself. you have to get the active language every time you call |
0 replies
or you can use next-intl and then create new custom useRouter with progressbar from this package as follows import {createSharedPathnamesNavigation} from 'next-intl/navigation';
import NProgress from 'nprogress';
import { NavigateOptions } from 'next/dist/shared/lib/app-router-context.shared-runtime';
export const locales = ['en', 'de'] as const;
export const localePrefix = 'always'; // Default
export const {Link, redirect, usePathname, useRouter: useIntlRouter} = createSharedPathnamesNavigation({locales, localePrefix});
// create custom useRouter
export function useRouter() {
const router = useIntlRouter();
const pathname = usePathname();
function push(href: string, options?: NavigateOptions) {
const targetUrl = new URL(href, location.href);
const currentUrl = new URL(location.href);
const hasSearchParams = targetUrl?.searchParams?.toString() !== currentUrl?.searchParams?.toString();
const paramsChanged = hasSearchParams && targetUrl?.search !== currentUrl?.search;
if (targetUrl.pathname === pathname && !paramsChanged) return Promise.resolve(true);
NProgress.start();
return router.push(href, options);
}
function replace(href: string, options?: NavigateOptions) {
const targetUrl = new URL(href, location.href);
if (targetUrl.pathname === pathname) return Promise.resolve(true);
NProgress.start();
return router.replace(href, options);
}
return { ...router, push, replace };
}nprogress is intalled by default with the package |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Describe the error
No next-lint integration.
When we add
import { useRouter } from 'next13-progressbar';and we use
<button onClick={() => router.push('/dashboard ')}>ButtonLink</button>the selected language is not saved.
To Play
Steps to reproduce the behavior:
http://localhost:3000/dashboardhttp://localhost:3000/en/dashboard<button onClick={() => router.push('/dashboard ')}>ButtonLink</button>http://localhost:3000/dashboardExpected Behavior
Save the selected language
All reactions