not-found.js returning some warnings
Answered
Elite posted this in #help-forum
EliteOP
So for my "transactions", if my database doesn't recall an ID, i prompt a
Here is my not-found.js:
when I go to a random url, I get these warnings:
---
---
and same with new head and new body comp
noteFound()export default async function TransactionDisplayPage({ params }) {
let data = await fetchID(params.id);
if (data === null) { // no transaction found
notFound();
// return (<h1>404</h1>)
}
...Here is my not-found.js:
import Link from 'next/link'
export default function NotFound() {
return (
<div style={{
position: 'absolute',
left: '50%',
top: '50%',
transform: 'translate(-50%, -50%)',
color: 'red'
}}>
<h1>404 Not Found! | <Link href="/" style={{color: 'red', textDecoration: 'underline'}}><strong>Go Back Home</strong></Link></h1>
</div>
);
}when I go to a random url, I get these warnings:
app-index.js:35 Warning: validateDOMNesting(...): <html> cannot appear as a child of <body>.
at html---
Warning: You are mounting a new html component when a previous one has not first unmounted. It is an error to render more than one html component at a time and attributes and children of these components will likely fail in unpredictable ways. Please only render a single instance of <html> and if you need to mount a new one, ensure any previous ones have unmounted first.---
and same with new head and new body comp
71 Replies
@Arinji show your nearest layout.tsx please
EliteOP
// import Navbar from '@components/General/navbar.jsx';
// import Footer from '@components/General/Footer.jsx';
export const metadata = {
title: 'PayBridge Technologies - Transaction'
}
export default function TransactionLayout({ children }) {
return (
<html lang="en">
<head/>
<body>
{/* <Navbar/> */}
{children}
{/* <Footer/> */}
</body>
</html>
)
}in the route
@Elite yes
ok do a vscode search for <html> and show the results
EliteOP
you cant have 2 html tags
Answer
cause the layout.js is ALWAYS going to be on the site
EliteOP
so should i remove them in the internal layout
having another layout with html will make the page have 2
EliteOP
like the route layout
EliteOP
alr
export default function TransactionDataLayout({ children }) {
return (
<head/>
<body>
{children}
</body>
)
}what should i do to this
jsx
EliteOP
its redlined
your file extensions need to be jsx
not js
EliteOP
even for error and notfound?
all react components :D
EliteOP
bascially everything but backend
alr
js dosent have html tags
jsx has html tags
EliteOP
still red
@Elite still red
show your entire file
EliteOP
all my layouts are red except the root
i mean the file, not fileStructure
EliteOP
export const metadata = {
title: 'Application'
}
export default function ApplicationLayout({ children }) {
return (
<head/>
<body>
{children}
</body>
)
}EliteOP
💀
theres no head anymore right
mhm lol
EliteOP
how did i not see this error anywhere
except when i gto a 404 page
not sure tbh, its just a very bad thing to do so nextjs goes all funky
EliteOP
ye
so errors?
np
@Arinji np
EliteOP
hey just wondering does
still work?
import Head from 'next/head'still work?
or deprecated
@Elite hey just wondering does
js
import Head from 'next/head'
still work?
it doesn't work in app router but It still work in page router
@Ray it doesn't work in app router but It still work in page router
EliteOP
so its the metadata api now in app router
how can I use that in client pages?
how can I use that in client pages?
@Elite so its the metadata api now in app router
how can I use that in client pages?
it is available on server only
EliteOP
so if I want to do those tags on client what can I do
@Elite so if I want to do those tags on client what can I do
make a server component, call your client component from it
also make a new forum for this plz
@Arinji also make a new forum for this plz
@Ray why you not say this

EliteOP
shit mb
np
its just that we get points on the leaderboards lol
from getting answers marked
thats why most of us hang out here :D
@Arinji <@743561772069421169> why you not say this<:wat:1220772839636992112>
because I already have too much points
@Ray because I already have too much points
stfu, i need points