I'm running a Next.js dev server. When I go to page #1, then click a link to page #2, it works great. (Just to clarify, I'm not using the as
prop of Next's <Link>
tag, just the regular old href
.)
However, if I then refresh page #2, the page itself loads, as do all the images ... but all of the Javascript files fail with a 404:
http://localhost:3000/page2/_next/static/chunks/main.js?ts=1612664646023 net::ERR_ABORTED 404 (Not Found) 2localhost/:196 GET
http://localhost:3000/page2/_next/static/development/_buildManifest.js?ts=1612664646023 net::ERR_ABORTED 404 (Not Found) 2localhost/:1 GET
http://localhost:3000/page2/_next/static/chunks/webpack.js?ts=1612664646023 net::ERR_ABORTED 404 (Not Found) 7localhost/:196 GET
http://localhost:3000/page2/_next/static/chunks/main.js?ts=1612664646023 net::ERR_ABORTED 404 (Not Found)
Does anyone know what I can do to fix this?
js comes with a default 404 page. It is a static page, and you can use getStaticProps for data fetching inside this page. However, the default 404 page doesn't have a header, footer, or other links. So, it is recommended to use the normal layout of your Next.
HTML Error Appears. When an HTTP 404 appears on your screen, it means that although the server is reachable, the specific page you are looking for is not. The web page is either broken, or it no longer exists. The 404 error code can appear in any browser, regardless of the type of browser you are using.
Ran into similar problem with inherited code, search a million times this was the top result. My answer for all other frustrated dev out there, check your 'Link' and your 'router.push()' especially if you are using a custom router. The Link and router.push() should be pointing to the server url. You can pass 'as' to mask the url for the browser.
In our case we fixed it by skipping the next.js router for handling the URL:
<Link
onClick={() => {
const url = '/path/to/url';
Router.events.emit("routeChangeStart", url);
window.location.href = url;
}}
>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With