Route Management
Route protection means, protecting any route from unauthorized access.
Route protection means, protecting any route from public access. For example, sign-in or signup pages are public pages and any user can access them. However there are many pages that only authenticated users can access, those paths are called protected routes. In Crema, we have provided the functionality of route protection.
Mainly in Crema, we have three different types of route structures as below described
Create a new route
To create a new route, We need to follow two steps as below. For example, we are adding a new page named Sample Page with the URL "/sample-page"
Step 1. (Add Sidebar Menu): To allow access to the navigation menu for a particular user role. you need to go to the src/@crema/core/AppRoutes/routeConfig.js
file, In this file, we declared all the navigation(route) menus. We want to bind the particular menu with the user role then we assign the role to the route menu.
While we assign a role to the route menu, you have to pass one extra property named "permittedRole" in the menu object in order to make the menu protected based on the user role.
Don't need to add those routes in this config file that don't belong to the left sidebar
Step 2. (Add new Route): We need to create a new file in our desired route group. we are creating it in(protected)
group. On this path like belowsrc/app/(protected)/sample-page/page.js
Step 3. (Link with new Route): In this last step you need to create your page(Sample Page) and link that with the newly created routes. To create a new page, we need to go into the modules directory and create a new directory named SamplePage and its index file with the following code.
All Done! You can create any routes by following the above few simple steps.
Last updated