styling dissapearing from 404 page after switching to an existent page
Answered
Saltwater Crocodile posted this in #help-forum
Saltwater CrocodileOP
hello! I'm having an issue where whenever i first start the site, and i load a non-existent page, the styling works fine. but as soon as i switch to a existent one and switch back to one that would render the 404 page, it has no styling anymore. how can i fix this?
Answered by Saltwater Crocodile
yeah i got it working with some weird workaround: https://stackoverflow.com/questions/76230464/next-js-13-remove-layout-for-specific-page
22 Replies
Saltwater CrocodileOP
here's the page with styling (first page loaded):
but after switching it looks like this:
not-found.tsx
import DefaultNotFound from '@/app/ui/default-not-found';
export default function NotFound() {
return (
<DefaultNotFound />
);
}
/ui/default-not-found.tsx
import { MagnifyingGlassIcon } from '@heroicons/react/24/outline';
import Link from 'next/link';
export default function NotFound() {
return (
<main className="flex h-screen flex-col items-center justify-center gap-4 -mt-8">
<MagnifyingGlassIcon className="w-10 text-gray-400" />
<h2 className="text-3xl font-bold text-gray-700">404 - Not Found</h2>
<p className="text-lg text-gray-500">
The page you requested could not be found.
</p>
<Link href="/" className="inline-flex items-center px-4 py-2 rounded-md text-sm font-medium text-center text-white bg-blue-600 hover:bg-blue-700">
Return Home
</Link>
</main>
);
}
layout.tsx:
import '@/app/ui/global.css';
export default function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
return (
<html lang="en">
<body>
{children}
</body>
</html>
);
}@ᴉuɐpɹɐɐ this on dev or on build?
Saltwater CrocodileOP
dev
@Saltwater Crocodile dev
whats your Next.js version?
and does it occur in build?
@ᴉuɐpɹɐɐ whats your Next.js version?
Saltwater CrocodileOP
newest one
@ᴉuɐpɹɐɐ and does it occur in build?
Saltwater CrocodileOP
what the flip does that mean
i haven’t put it into production
i’ve just been running it whilst working on it on localhost
@Saltwater Crocodile what the flip does that mean
run
npm run build and then npm run startbuild your project and start the built server and see if it persists
lol
Saltwater CrocodileOP
okay
i will do it tmr
thanks
no worries, lmk later
Saltwater CrocodileOP
yessir
@ᴉuɐpɹɐɐ no worries, lmk later
Saltwater CrocodileOP
it did not work
Saltwater CrocodileOP
ok i have no clue what's going on but now its working?
Saltwater CrocodileOP
yeah i got it working with some weird workaround: https://stackoverflow.com/questions/76230464/next-js-13-remove-layout-for-specific-page
Answer