Add New Route
In the Nextjs app we have to add routes in the src/pages directory. this is the default route directory of the Nextjs. To add new route in the Nextjs you need to follow the following two steps.
In the First step, If you wants to add new menu in the sidebar, you need to follow the following steps.
Go to the file with the path: -
Adding a group of menu's:-
If you want to add a group of menus, Just add a new object in the above-said file with the following properties as shown below-
The children's property of a group contains objects as shown below.
Adding Collapse type Menu:-
To add a collapse type menu, go to the 'routesConfig' file (path given in step 1) and add a new object to the 'routesConfig' array. The new object show look like this:-
Adding a menu item:-
Adding a menu item is very easy, You just have to add an object in the 'routesConfig' array in the 'routesConfig' file (path given in step 1). The Item object should look contain the following properties as shown in the screenshot shown below.
In the nutshell, You just have to add an object in order to array a new menu. The object contains a property named 'type' which can have three values i.e. 'group', 'collapse', and 'item'. You just have to pass the correct value to this 'type' property as per the type of menu you want to add. All other properties in the object remain the same
In the second step you need to add route in your app. To add route in your next app you need to follow the following steps. If you want to add a new route name new-page then you need to create a file in page directory and follow the further steps written below. In the Nextjs app we have two types of route. One is protected and second in public routes. You can add them like below.
Public Routes: To add public routes you need to wrap your components in the following wrapper like below
Protected Routes: To add protected routes you need to wrap your components in the following wrapper like below
Last updated