Open schemburkar opened 1 year ago
Sample Gif of the repro bug
I am facing the same issue. Classic example is the shop product list with /product/[id] that opens a preview modal. When user click on "See full details" button in the modal, we want to show the original route (product page) to the user.
Proposition is to have a property bypassRouteInterception
in <Link>
. It preloads and redirect to the original product page.
<Link href={`/product/${id}`} bypassRouteInterception>See full details</Link>
The workaround is:
onClick={() => { window.location.reload(); }}
@louisthomaspro The reload workaround works for your use case perfectly. For me, I'm already on the search page. To update the search results, the router.replace(newUrl)
shows modal for me!
The page should be intercepted when user is on another route. Once they are on the actual page, there should not be requirement to intercept the same route anymore!!!
Proposition is to have a property
bypassRouteInterception
in<Link>
. It preloads and redirect to the original product page.<Link href={`/product/${id}`} bypassRouteInterception>See full details</Link>
Something like this would be really useful. For my use-case I want the modal to have a ...Read More
button which would open the full page view
Am facing the same issue. Looking forward to a fix for this
Any update on this? I'm using query strings for variant selection on a product page. The product page is being shown in a modal using intercepting routes. When the page is visited directly, selecting a variant causes the modal to be displayed.
Proposition is to have a property
bypassRouteInterception
in<Link>
. It preloads and redirect to the original product page.<Link href={`/product/${id}`} bypassRouteInterception>See full details</Link>
Something like this would be really useful. For my use-case I want the modal to have a
...Read More
button which would open the full page view
I like that API. Any update?
Facing the same issue, any update on this. Preferably search params should not trigger the modal to open.
We need the same functionality. bypassRouteInterception
feels like a clean API to me 👍
Our case is that we're using clerk for auth, and in some cases we want the clerk signin / signup components to appear in a modal, and other times not.
anyone found any soludtion . please let me know
@sarowarhosen03
anyone found any soludtion . please let me know
You could use a normal Anchor tag:
<a href=href={"/product/" + slug}>View more details</a>
@sarowarhosen03
anyone found any soludtion . please let me know
You could use a normal Anchor tag:
<a href=href={"/product/" + slug}>View more details</a>
what if i need to do it with JavaScript i i can use window.location.replace but the main problem is both are making hard reload and broke the single page application experience
@sarowarhosen03
I set it up so the root page triggers the modal. It's not an ideal workaround but at least you don't have the same view rendering on top of itself. I also had to pass in the route to go back to when the modal closes.
"use client";
import { usePathname, useRouter, useSearchParams } from "next/navigation";
import { useEffect } from "react";
export default function SearchStocksPage({
searchParams: { query },
}: {
searchParams: { query?: string };
}) {
const pathname = usePathname();
const router = useRouter();
const searchParams = useSearchParams();
let done = false;
useEffect(() => {
if (!done) {
done = true;
router.push(`${pathname}?${searchParams.toString()}`);
}
}, []);
}
i think i got a solution by making a seperate utility function
"use server";
import { redirect } from "next/navigation";
export default async function redirectHard(uri) {
redirect(uri);
}
then call it from your client component
Any workarounds for when url query params are updated (via JS nuqs & non-shallow param replacements)?
Currently the only workaround i've found is to redirect to another route.
app/@search/(.)searchy/page.tsx
)app/searchy/page.tsx
), which just redirects to /search.app/search/page.tsx
) and is able to non-shallow update the url query params.// app/searchy/page.tsx
import { redirect, RedirectType } from 'next/navigation';
/**
* There is a bug where updating url query params (non-shallow) causes the modal to appear on the full page route.
* https://github.com/vercel/next.js/issues/51648
*
* So we open the modal under /searchy and the full page route for /searchy will soft redirect to /search.
*/
export default function Page(props: any): any {
console.log('searchy page props', props);
const params = new URLSearchParams(props.searchParams);
const newPath = `/search?${params.toString()}`;
redirect(newPath, RedirectType.replace);
}
Hacky
Any workarounds for when url query params are updated (via JS nuqs & non-shallow param replacements)?
Currently the only workaround i've found is to redirect to another route.
- So if my modal opens under /searchy (
app/@search/(.)searchy/page.tsx
)- A refresh will open the full page route of /searchy (
app/searchy/page.tsx
), which just redirects to /search.- User then lands on the full page route for /search (
app/search/page.tsx
) and is able to non-shallow update the url query params.// app/searchy/page.tsx import { redirect, RedirectType } from 'next/navigation'; /** * There is a bug where updating url query params (non-shallow) causes the modal to appear on the full page route. * https://github.com/vercel/next.js/issues/51648 * * So we open the modal under /searchy and the full page route for /searchy will soft redirect to /search. */ export default function Page(props: any): any { console.log('searchy page props', props); const params = new URLSearchParams(props.searchParams); const newPath = `/search?${params.toString()}`; redirect(newPath, RedirectType.replace); }
Hacky
Any workarounds for when url query params are updated (via JS nuqs & non-shallow param replacements)?
Currently the only workaround i've found is to redirect to another route.
- So if my modal opens under /searchy (
app/@search/(.)searchy/page.tsx
)- A refresh will open the full page route of /searchy (
app/searchy/page.tsx
), which just redirects to /search.- User then lands on the full page route for /search (
app/search/page.tsx
) and is able to non-shallow update the url query params.// app/searchy/page.tsx import { redirect, RedirectType } from 'next/navigation'; /** * There is a bug where updating url query params (non-shallow) causes the modal to appear on the full page route. * https://github.com/vercel/next.js/issues/51648 * * So we open the modal under /searchy and the full page route for /searchy will soft redirect to /search. */ export default function Page(props: any): any { console.log('searchy page props', props); const params = new URLSearchParams(props.searchParams); const newPath = `/search?${params.toString()}`; redirect(newPath, RedirectType.replace); }
Hacky
Instead of doing this redirect from server using a server action might be a good option
Verify canary release
Provide environment information
Which area(s) of Next.js are affected? (leave empty if unsure)
App directory (appDir: true)
Link to the code that reproduces this issue or a replay of the bug
https://codesandbox.io/p/sandbox/dazzling-hooks-fz6pjv
To Reproduce
The search modal should not show up.
Describe the Bug
/search
route in a ModalAll Good so far.
/search?q=food
/search
route in a ModalSince the user is already on the full
/search
page, there should not be any requirement to again open the intercepted routeExpected Behavior
When updating the route with a new query string, the page should get updated and not show the intercepted route modal. As the page is already loaded and should not be again intercepted.
Which browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response