My navbar duplicating itself
Answered
Acorn-plum gall posted this in #help-forum
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Acorn-plum gallOP
import Navbar from '@/components/templates/Header/Header'
import Head from 'next/head'
import Cont from '@/components/templates/Header/contnt'
function First() {
return (
<Head>
<title>Buy the best paintings in Belarus</title>
<meta charSet='UTF-8' />
<meta httpEquiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width-device-width, initial-scale=1.0" />
<link rel='icon' type='image/svg' sizes='32x32' href='/img/favicon.png' />
<div>
<body>
<Navbar />
<Cont />
</body>
</div>
</Head>
)
}
export default First
Answered by risky
yes^ your app file has it imported, so importing it here is useless/ harmful
137 Replies
![Avatar](https://cdn.discordapp.com/avatars/194128415954173952/708a8637ada505b6b7a85972807d9dca.webp?size=256)
Alfonsus Ardani
you put a div inside head? 🤨
![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/aff4eeb34922ca980b0d5fbb5bc60c21.webp?size=256)
risky
is this the only import of Navbar in your code?
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Acorn-plum gallOP
im a rookie
no
i also have other
and they are the same
so what should i do, remove div from head? right?
![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/aff4eeb34922ca980b0d5fbb5bc60c21.webp?size=256)
risky
what about first? is that imported many times? / where is that used?
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Acorn-plum gallOP
zero
that was from tutor
![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/aff4eeb34922ca980b0d5fbb5bc60c21.webp?size=256)
risky
your function
First
isn't used anywhere?so it isn't being used then?
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Acorn-plum gallOP
oh wait
its for routing
i know its usless
but i imported it only as a route
![Avatar](https://cdn.discordapp.com/avatars/839454110302732309/d3f0b9db767484084f52339f0b4f2385.webp?size=256)
dumbboy
First of all, what is
First
component![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Acorn-plum gallOP
Route
![Avatar](https://cdn.discordapp.com/avatars/839454110302732309/d3f0b9db767484084f52339f0b4f2385.webp?size=256)
dumbboy
Using 13 app dir?
![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/aff4eeb34922ca980b0d5fbb5bc60c21.webp?size=256)
risky
its pages dir
bc you can't import head in app dir
![Avatar](https://cdn.discordapp.com/avatars/839454110302732309/d3f0b9db767484084f52339f0b4f2385.webp?size=256)
dumbboy
He might be, you never know
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Acorn-plum gallOP
bruh, all code is ucked fup
![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/aff4eeb34922ca980b0d5fbb5bc60c21.webp?size=256)
risky
also, body inside head? idk how that goes
![Avatar](https://cdn.discordapp.com/avatars/839454110302732309/d3f0b9db767484084f52339f0b4f2385.webp?size=256)
dumbboy
It is, we are happy to help, if you explain a bit more
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Acorn-plum gallOP
im just really new in frontend
3 days or something
![Avatar](https://cdn.discordapp.com/avatars/839454110302732309/d3f0b9db767484084f52339f0b4f2385.webp?size=256)
dumbboy
Using Next.js after 3 days, not recommended, but anyways.
Can you show your project structure
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Acorn-plum gallOP
okay
![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/aff4eeb34922ca980b0d5fbb5bc60c21.webp?size=256)
risky
how do you start learning without using it?
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Acorn-plum gallOP
you need a screenshot right?
![Avatar](https://cdn.discordapp.com/avatars/839454110302732309/d3f0b9db767484084f52339f0b4f2385.webp?size=256)
dumbboy
Yeah
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Acorn-plum gallOP
![Image](https://cdn.discordapp.com/attachments/1151876611596099775/1151878447380058132/image.png)
![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/aff4eeb34922ca980b0d5fbb5bc60c21.webp?size=256)
risky
whats in app btw?
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Acorn-plum gallOP
lemme seee
axios
![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/aff4eeb34922ca980b0d5fbb5bc60c21.webp?size=256)
risky
and where is said First function and Navbar
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Acorn-plum gallOP
First in index tsx
and navbar in components
![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/aff4eeb34922ca980b0d5fbb5bc60c21.webp?size=256)
risky
so you are only using First in _app.tsx?
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Acorn-plum gallOP
no
![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/aff4eeb34922ca980b0d5fbb5bc60c21.webp?size=256)
risky
in index.tsx?
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Acorn-plum gallOP
yes
its defined there
![Avatar](https://cdn.discordapp.com/avatars/839454110302732309/d3f0b9db767484084f52339f0b4f2385.webp?size=256)
dumbboy
First of all, you should not put div inside Head component, first remove that from head and put outside
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Acorn-plum gallOP
okay
got an error
it have a quickfix
![Avatar](https://cdn.discordapp.com/avatars/839454110302732309/d3f0b9db767484084f52339f0b4f2385.webp?size=256)
dumbboy
What's the error?
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Acorn-plum gallOP
should i wrap it into a jsx component?
![Avatar](https://cdn.discordapp.com/avatars/839454110302732309/d3f0b9db767484084f52339f0b4f2385.webp?size=256)
dumbboy
Yeah
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Acorn-plum gallOP
JSX expressions must have one parent element.
![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/aff4eeb34922ca980b0d5fbb5bc60c21.webp?size=256)
risky
i think this should work better
import Navbar from '@/components/templates/Header/Header'
import Head from 'next/head'
import Cont from '@/components/templates/Header/contnt'
function First() {
return (
<>
<Head>
<title>Buy the best paintings in Belarus</title>
<meta charSet='UTF-8' />
<meta httpEquiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width-device-width, initial-scale=1.0" />
<link rel='icon' type='image/svg' sizes='32x32' href='/img/favicon.png' />
</Head>
<body>
<Navbar />
<Cont />
</body>
</>
)
}
export default First
![Avatar](https://cdn.discordapp.com/avatars/839454110302732309/d3f0b9db767484084f52339f0b4f2385.webp?size=256)
dumbboy
Yeah, like that above
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Acorn-plum gallOP
okay
give me a second
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Acorn-plum gallOP
div has no closing tag
![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/aff4eeb34922ca980b0d5fbb5bc60c21.webp?size=256)
risky
ahh yeah, remove it
![Avatar](https://cdn.discordapp.com/avatars/839454110302732309/d3f0b9db767484084f52339f0b4f2385.webp?size=256)
dumbboy
Just copy and paste this
![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/aff4eeb34922ca980b0d5fbb5bc60c21.webp?size=256)
risky
(he was right, i forgot to remove the last div, but i just fixed)
![Avatar](https://cdn.discordapp.com/avatars/839454110302732309/d3f0b9db767484084f52339f0b4f2385.webp?size=256)
dumbboy
Okay, I didn'tt notice
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Acorn-plum gallOP
still have second navbar at the bottom
![Avatar](https://cdn.discordapp.com/avatars/839454110302732309/d3f0b9db767484084f52339f0b4f2385.webp?size=256)
dumbboy
What is in Cont component?
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Acorn-plum gallOP
content cards
![Avatar](https://cdn.discordapp.com/avatars/839454110302732309/d3f0b9db767484084f52339f0b4f2385.webp?size=256)
dumbboy
Would you mind sharing it?
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Acorn-plum gallOP
why not
sec
![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/aff4eeb34922ca980b0d5fbb5bc60c21.webp?size=256)
risky
since you use vscode, can you do a global search for navbar and first and see if it is used anywhere else
![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/aff4eeb34922ca980b0d5fbb5bc60c21.webp?size=256)
risky
its important tho... he should see if it is used anywhere else as its showing up in 2 places
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Acorn-plum gallOP
import React from 'react';
import Link from 'next/link';
import styles from './cntnt2.module.css';
const Cont: React.FC = () => {
return (
<div>
<section className={styles.container}>
<div className={styles.card}>
<div className={styles.image1}></div>
<h2 className={styles.h2}>О наÑ</h2>
<p className={styles.p}>ПредÑтавлÑем вам магазин Ðкрилат - поÑтавщик краÑок номер 1 на территории РБ, на Ñтой Ñтранице вы можете изучить наших клиентов, отзывы и другие детали...</p>
</div>
<div className={styles.card}>
<div className={styles.image}></div>
<h2>Title</h2>
<p>Text</p>
</div>
<div className={styles.card}>
<div className={styles.image}></div>
<h2>Title</h2>
<p>Text</p>
</div>
<div className={styles.card}>
<div className={styles.image}></div>
<h2>Title</h2>
<p>Text</p>
</div>
<div className={styles.card}>
<div className={styles.image}></div>
<h2>Title</h2>
<p>Text</p>
</div>
</section>
</div>
);
};
export default Cont;
![Avatar](https://cdn.discordapp.com/avatars/839454110302732309/d3f0b9db767484084f52339f0b4f2385.webp?size=256)
dumbboy
Okay, can you share your _document.tsx and _app.tsx?
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Acorn-plum gallOP
.container{
margin-top: 10%;
display:flex;
justify-content: center;
flex-wrap: wrap;
}
.card{
background: white;
width:270px;
height:400px;
margin: 10px;
border-radius: 15px;
}
.h2{
padding:5px;
text-align: center;
}
.p{
padding: 5px;
text-align: center;
}
.image1{
border-radius: 15px;
border-bottom-left-radius: 0%;
border-bottom-right-radius: 0%;
background-image: url(./logo.png);
height: 200px;
margin-bottom: 15px;
background-size: cover;
}
.card:hover{
transform:scale(1.05);
cursor: pointer;
background-color: rgb(57, 59, 59);
color:azure;
transition: 0.2s ease;
}
sec
Document tsx
import { Html, Head, Main, NextScript } from 'next/document'
export default function Document() {
return (
<Html lang="en">
<Head />
<body>
<Main />
<NextScript />
</body>
</Html>
)
app tsx
import '@/styles/globals.css'
import React from 'react';
import Header from '../components/templates/Header/Header';
import { AppProps } from 'next/app';
const MyApp: React.FC<AppProps> = ({ Component, pageProps }) => {
return (
<div>
<Header />
<Component {...pageProps} />
</div>
);
};
export default MyApp;
![Avatar](https://cdn.discordapp.com/avatars/839454110302732309/d3f0b9db767484084f52339f0b4f2385.webp?size=256)
dumbboy
Okay, since you already using header in app.tsx, you don't need to put it in your any pages.
![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/aff4eeb34922ca980b0d5fbb5bc60c21.webp?size=256)
risky
wrong
![Avatar](https://cdn.discordapp.com/avatars/839454110302732309/d3f0b9db767484084f52339f0b4f2385.webp?size=256)
dumbboy
It will automatically render at every page.
Why?
![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/aff4eeb34922ca980b0d5fbb5bc60c21.webp?size=256)
risky
in document, you import if from next/document so next knows where to put the head component
![Avatar](https://cdn.discordapp.com/avatars/839454110302732309/d3f0b9db767484084f52339f0b4f2385.webp?size=256)
dumbboy
Okay, So?
@Acorn-plum gall Did it work?
![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/aff4eeb34922ca980b0d5fbb5bc60c21.webp?size=256)
risky
ahh i thought you were talking about document, not app...
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Acorn-plum gallOP
wait
lilbit
![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/aff4eeb34922ca980b0d5fbb5bc60c21.webp?size=256)
risky
but the problem could be from header importing twice or being imported in app and the new page
That's what I said
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Acorn-plum gallOP
import Navbar from '@/components/templates/Header/Header'
import Head from 'next/head'
import Cont from '@/components/templates/Header/contnt'
function First() {
return (
<>
<Head>
<title>Buy the best paintings in Belarus</title>
<meta charSet='UTF-8' />
<meta httpEquiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width-device-width, initial-scale=1.0" />
<link rel='icon' type='image/svg' sizes='32x32' href='/img/favicon.png' />
</Head>
<header>
<body>
<Navbar />
<Cont />
</body>
</header>
</>
)
}
export default First
no
![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/aff4eeb34922ca980b0d5fbb5bc60c21.webp?size=256)
risky
(can you stop with the gifs... just wait for his reponse..)
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Acorn-plum gallOP
or maybe im just stupid
![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/aff4eeb34922ca980b0d5fbb5bc60c21.webp?size=256)
risky
header inside body...
![Avatar](https://cdn.discordapp.com/avatars/839454110302732309/d3f0b9db767484084f52339f0b4f2385.webp?size=256)
dumbboy
Don't add Navbar Again in your FIrst component
![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/aff4eeb34922ca980b0d5fbb5bc60c21.webp?size=256)
risky
yes^ your app file has it imported, so importing it here is useless/ harmful
Answer
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Acorn-plum gallOP
how i added it again?
![Avatar](https://cdn.discordapp.com/avatars/839454110302732309/d3f0b9db767484084f52339f0b4f2385.webp?size=256)
dumbboy
You are importing it and using in body again.
![Image](https://cdn.discordapp.com/attachments/1151876611596099775/1151881969693622382/Screenshot_2023-09-14_at_7.37.01_PM.jpg)
Don't use it
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Acorn-plum gallOP
oh so
its placing itself without me typing <Navbar/>????
![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/aff4eeb34922ca980b0d5fbb5bc60c21.webp?size=256)
risky
you have imported it twice
![Avatar](https://cdn.discordapp.com/avatars/839454110302732309/d3f0b9db767484084f52339f0b4f2385.webp?size=256)
dumbboy
Yeah, everyting you place at app.tsx, renders at each page
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Acorn-plum gallOP
ye i got it
![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/aff4eeb34922ca980b0d5fbb5bc60c21.webp?size=256)
risky
one in app and other in that component
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Acorn-plum gallOP
oh
so im just a dumb idiot who should just import it in the app tsx
![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/aff4eeb34922ca980b0d5fbb5bc60c21.webp?size=256)
risky
the component already has the code from app, so you don't need to import twice
![Avatar](https://cdn.discordapp.com/avatars/839454110302732309/d3f0b9db767484084f52339f0b4f2385.webp?size=256)
dumbboy
Not idiot, more like new
Anyways, is your problem solved?
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Acorn-plum gallOP
bruh
wait pls
![Image](https://cdn.discordapp.com/attachments/1151876611596099775/1151882826212446302/image.png)
its not duplicating anymore
but i have this error now
![Avatar](https://cdn.discordapp.com/avatars/839454110302732309/d3f0b9db767484084f52339f0b4f2385.webp?size=256)
dumbboy
You don't use body inside header, and don't use body in pages
No need to write body tag
Just write your code
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Acorn-plum gallOP
YEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEES
FINALLY
![Avatar](https://cdn.discordapp.com/avatars/839454110302732309/d3f0b9db767484084f52339f0b4f2385.webp?size=256)
dumbboy
Congrats
![Avatar](https://cdn.discordapp.com/avatars/657067112434499595/aff4eeb34922ca980b0d5fbb5bc60c21.webp?size=256)
risky
even i am confused on what you mean by this?
but it works so 🎉
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Acorn-plum gallOP
EVERY GOD IN THE WORLD BLESS GUYS
![Avatar](https://cdn.discordapp.com/avatars/839454110302732309/d3f0b9db767484084f52339f0b4f2385.webp?size=256)
dumbboy
And please select the message that helped you and mark it as solution.
I'm not forcing to do it for my message BTW
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Acorn-plum gallOP
wait
![Avatar](https://cdn.discordapp.com/avatars/839454110302732309/d3f0b9db767484084f52339f0b4f2385.webp?size=256)
dumbboy
Edited the message, I typed in hurry
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Acorn-plum gallOP
how to chose it![:mild_panic:](https://cdn.discordapp.com/emojis/770004383886737418.png)
![:mild_panic:](https://cdn.discordapp.com/emojis/770004383886737418.png)
![Avatar](https://cdn.discordapp.com/avatars/839454110302732309/d3f0b9db767484084f52339f0b4f2385.webp?size=256)
dumbboy
hover on message, click on the three dots, apps -> mark as solution
![Avatar](https://cdn.discordapp.com/embed/avatars/5.png)
Acorn-plum gallOP
oh i didnt seen that
ill try again
thanks again guys
im closing it