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 interface Menuitemtype {
	menutitle?: string;
	path?: string;
	title?: string;
	icon?: any;
	type?: 'link' | 'empty' | 'sub';
	active?: boolean;
	selected?: boolean;
	dirchange?: boolean;
	children?: Menuitemtype[];
	badgetxt?: string;
	class?: string;
	menusub?: boolean;
  }

// icons

const dashboardsvg = <svg xmlns="http://www.w3.org/2000/svg" className="side-menu__icon" viewBox="0 0 24 24" >
                     <path d="M0 0h24v24H0V0z" fill="none" /> <path d="M5 5h4v6H5zm10 8h4v6h-4zM5 17h4v2H5zM15 5h4v2h-4z" opacity=".3" />
          <path d="M3 13h8V3H3v10zm2-8h4v6H5V5zm8 16h8V11h-8v10zm2-8h4v6h-4v-6zM13 3v6h8V3h-8zm6 4h-4V5h4v2zM3 21h8v-6H3v6zm2-4h4v2H5v-2z" /></svg>

export const MENUITEMS: Menuitemtype[] = [
{ menutitle: "MAIN" },

{ path: "/components/dashboard/dashboard", icon: dashboardsvg, badgetxt:"1", class:"badge bg-success ms-auto menu-badge",  type: "link", active: false, selected: false, dirchange: false, title: "Index" },

{ menutitle: "GENERAL" },

{ path: "/components/icons/icon", icon: iconsvg, type: "link", active: false, selected: false, dirchange: false, title: "Icons" },
]