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 |
Beta Was this translation helpful? Give feedback.
-
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 |
Beta Was this translation helpful? Give feedback.
-
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/dashboard
http://localhost:3000/en/dashboard
<button onClick={() => router.push('/dashboard ')}>ButtonLink</button>
http://localhost:3000/dashboard
Expected Behavior
Save the selected language
Beta Was this translation helpful? Give feedback.
All reactions