-
Notifications
You must be signed in to change notification settings - Fork 27k
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
Intercepting routes do not work with redirect
from next/navigation
#54676
Comments
Think there is a bug with redirect not working if you use absolute url like |
I'm having the same issue. It's my first time using redirect and it plain doesn't work for a simple thing like redirecting to |
A bit upsetting: In the last cannary versions I don't see (at least in change list) any fixes. There is so much blocking breakage in routing and parallel routes, its scary. About to jump of on new projects from using next, were we already initiated and are in early phase of development. Lack of proper marking of experimental / alpha state code is something every dev should pay strong attention to. Going back to the stack used in previous projects that work well. I just hoped some layout and routing improvements that I've seen in nextjs13, but exactly that is very broken out of experimental phase. |
The documentation says (https://nextjs.org/docs/app/api-reference/functions/redirect):
In Server Components and Client Components, you should use redirect() only during its rendering (just like the example showed in the documentation). To do redirection in other situations you can use useRouter() (router.push()). I would suggest to clarify this in the documentation, because the first time I read it I thought I could use redirect() just like router.push(). |
Having the same issue, I'm using it in a server action function which handles a search input server component, It's annoying that it only succueed serveral times then the whole page goes to no responding. |
In the situation you are using TestI've tried to replicate the issue with a basic test in File structure:
Code: // app/page.js
import ClientComponent from "./ClientComponent";
export default function Home() {
return (
<main>
<ClientComponent />
</main>
)
} // app/ClientComponent.jsx
'use client'
import { myAction } from './actions'
export default function ClientComponent() {
return (
<form action={myAction}>
<button type="submit">Add to Cart</button>
</form>
)
} // app/actions.js
'use server'
import { redirect } from "next/navigation"
export async function myAction() {
console.log('Server Action')
redirect('/blog')
} // app/blog/page.js
"use client"
import { useState } from "react"
export default function Home() {
const [counter, setCounter] = useState(0)
return (
<main>
<h1>Blog</h1>
<h3>{counter}</h3>
<button type="button" onClick={() => setCounter(counter + 1)}>+</button>
</main>
)
} |
@Diego-0110 It only suscceed serveral times, when I make some other operations and then trigger it,it would fali and the whole page goes to no responding. |
This comment has been minimized.
This comment has been minimized.
Thank you for creating a reproduction. I just took a look here and have confirmed this is working as expected on My understanding is that server-side redirects with Secondly, "use client";
import { navigate } from './actions';
export function ClientRedirect() {
return (
<form action={navigate}>
<input type="text" name="id" placeholder="id" />
<button>Go</button>
</form>
);
} 'use server';
import { redirect } from 'next/navigation';
export async function navigate(data: FormData) {
redirect(`/foo/${data.get('id')}`);
} CleanShot.2023-12-30.at.14.01.45.mp4 |
Based on feedback from vercel#54676.
This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Verify canary release
Provide environment information
Operating System: Platform: darwin Arch: arm64 Version: Darwin Kernel Version 22.6.0: Wed Jul 5 22:22:05 PDT 2023; root:xnu-8796.141.3~6/RELEASE_ARM64_T6000 Binaries: Node: 18.12.0 npm: 9.6.0 Yarn: 1.22.19 pnpm: N/A Relevant Packages: next: 13.4.20-canary.10 eslint-config-next: N/A react: 18.2.0 react-dom: 18.2.0 typescript: 5.2.2 Next.js Config: output: N/A
Which area(s) of Next.js are affected? (leave empty if unsure)
App Router, Routing (next/router, next/navigation, next/link)
Link to the code that reproduces this issue or a replay of the bug
https://github.com/acifani/intercepting-route-server-action/
To Reproduce
To reproduce the bug from my repo
Generally
Have an intercepted page (see example structure from repro repo) and navigate to the route of that page using
redirect
fromnext/navigation
.The bug appears both on Vercel and locally.
Describe the Bug
This is the file structure in the repro project
Using
router.push
fromuseRouter
works just as expected:But using
redirect
fromnext/navigation
does not work. A network call is made, but the page is not shown.The bug appears both in client components or server components using Server Actions
Expected Behavior
The intercepted page should work the same way for
router.push
andredirect
Which browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
The text was updated successfully, but these errors were encountered: