Routing configuration - MukeshKumar101/IPL_Auction GitHub Wiki
Problem Statement:
To write routing configuration for application
Jobs to be Done
- Create Protected Route
- Validate route based on permission
Implementation Plan
Create Protected Route
- Create add.route.js
- Create component ProtectedRoute
- Pass arguments like component as Component, role, path, properties of component using rest operator ..rest
- ProtectedRoute should return a Route
Validate route based on permission
- Import 'path.json' file as permission
- Define a validatePath method in add.route.js
- Pass permission, role, path as arguments to validatePath method
- In validatePath(permission, role, path)
- Get index of given path by indexOf() and store it in a variable index
- If index is not equal to -1, return true
- Else return false
- Get the return value by invoking validatePath(permission, role, path) and store in a variable isAllowed
- Pass path and properties of component to Route in render() method of ProtectedRoute component.
- If isAllowed is true, then render <Component>
- And Pass props to <Component {..props}>
- Else Redirect to '/' page