NEXTJs Routing

Routing

In a single-page application, you change what the user sees by showing or hiding portions of the display that correspond to particular components, rather than going out to the server to get a new page. As users perform application tasks, they need to move between the different views that you have defined

To handle the navigation from one view to the next, you use the React Router. The Router enables navigation by interpreting a browser URL as an instruction to change the view. Your complete route structure is place at index.tsx file under pages » index.tsx

Suppose you want to create a new module ( For creating a new module refer create new module ) then you have to add new routes for that modules.


Basic Route

Following are the fundamental building blocks to creating a route.

 
	                    import React, { Fragment } from "react";
                        import Link from 'next/link';
	                    import { useRouter } from "next/router";
	              						
							<ul>
							    <li>
								   <Link href="/">Home
								   </Link>
								   </li>
								<li>
									<Link href="/about">About Us
									</Link>
								</li>
								<li>
									<Link href="/blog/hello-world">Blog Post
								    </Link>
							    </li>
							</ul>
							
Configure Link in Menu

To Add new link in Sidemenu

Following are the fundamental building blocks to creating a new link.


├── shared
├──layouts-components
├──sidebar
├──sidemenu.tsx

export const MENUITEMS = [
	{
		menutitle: "Main",
	},
		{
			title: "Dashboards",
			icon: (
				<svg
					xmlns="http://www.w3.org/2000/svg"
					className="side-menu__icon"
					width="24"
					height="24"
					viewBox="0 0 24 24"
				>
				<path d="M3 13h1v7c0 1.103.897 2 2 2h12c1.103 0 2-.897 2-2v-7h1a1 1 0 0 0 .707-1.707l-9-9a.999.999 0 0 0-1.414 0l-9 9A1 1 0 0 0 3 13zm7 7v-5h4v5h-4zm2-15.586 6 6V15l.001 5H16v-5c0-1.103-.897-2-2-2h-4c-1.103 0-2 .897-2 2v5H6v-9.586l6-6z" />
				</svg>
			),
			type: "sub",
			selected: false,
			active: false,
			children: [
				{
					path: "/components/dashboards/dashboard1",
					type: "link",
					active: false,
					selected: false,
					title: "Dashboard-1",
				},
				{
					path: "/components/dashboards/dashboard2",
					type: "link",
					active: false,
					selected: false,
					title: "Dashboard-2",
				},
				{
					path: "/components/dashboards/dashboard3",
					type: "link",
					active: false,
					selected: false,
					title: "Dashboard-3",
				},
			],
		},
]