-
Notifications
You must be signed in to change notification settings - Fork 27.5k
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
router.asPath different between server and front on 404 page #40617
Comments
Isn't this an expected behavior as stated here?
It was pre-rendered with import { useRouter } from 'next/router';
import { useEffect, useState } from 'react';
const Custom404 = () => {
const router = useRouter();
const [slug, setSlug] = useState<string>();
useEffect(() => {
setSlug(router.asPath.substr(1).replace(/([A-Z])/g, ' $1'));
}, [router]);
return <main>{slug}</main>;
};
export default Custom404; |
But router.asPath should return the same thing on server and client no ? Thank you for your quickfix anyway ;) |
If router.asPath is intended to return different content on server and on client this is not a bug then ... ;) |
I believe it is more of a side effect of pre-rendering rather than an intended effect. During pre-rendering inside the server, the router is unaware of the domain where it will be sent. It assumes its at /404 based on the filename, but it doesn't actually exists in a browser yet (its in the server, a server does not have a URL/web address). |
This issue has been automatically marked as stale due to two years of inactivity. It will be closed in 7 days unless there’s further input. If you believe this issue is still relevant, please leave a comment or provide updated details. Thank you. |
This issue has been automatically closed due to two years of inactivity. If you’re still experiencing a similar problem or have additional details to share, please open a new issue following our current issue template. Your updated report helps us investigate and address concerns more efficiently. Thank you for your understanding! |
Verify canary release
Provide environment information
What browser are you using? (if relevant)
Firefox developer edition 105.0b4 (64 bits)
How are you deploying your application? (if relevant)
No response
Describe the Bug
When accessing /someUnknownUrl
useRouter does not work consistently between browser and server on 404 page.
Expected Behavior
router.asPath should be '/someUnknownUrl' on server too
Link to reproduction
https://stackblitz.com/edit/vercel-next-js-ycc47c?file=pages/404.tsx
To Reproduce
Go to an unknownUrl
(https://vercel-next-js-ycc47c--3000.local-corp.webcontainer.io/unknownUrl)
You can see "Error: Text content does not match server-rendered HTML" caused by different rendering
The text was updated successfully, but these errors were encountered: