2-Creating basic Next JS app with links
2-Creating basic Next JS app with links
After creating the folder and opening it in vs code, run following command in terminal to make a
next js app.
npx create-next-app@latest
3. Inside folder src/app the Layout.tsx contains top part of the webpage which remains consistent
while user navigates to the different pages. Basic code of the Layout.tsx is as follows;
4. Inside the folder src/app the page.tsx file contains the definition of page below the layout for
the homepage of the website. Its sample code is as under;
function Home(props:any){
return(
<div>
<h2>This is Home page</h2>
<Link href="/about"> Zeeshan's Page </Link>
</div>
)
}
export default Home;
Note: import link as well as link tag is not mandatory here and is an alternative for HTML anchor tag.
5. Further pages inside the website are with the help of following 3 steps;
I. Add a folder inside scr/app in lower case letters. Name of this folder shall be the address of this
particular page of the website.
II. Add page.tsx file insider the folder.
III. Add following sample code inside the page.tsx file
function about(props:any){
return(
<div>
<h2>This is About page</h2>
</div>
)
}
export default about;
6. Make a folder dynamic route capable by adding [] across its name. Then by adding the following
code;