1.0.9 • Published 3 years ago
react-router-cli v1.0.9
React router CLI
What is this library for
react-router-cli - is a library for auto-generating react routing
Get started
- Install package globally
npm install --global react-router-cli - Initialize React app
npx create-react-app react-app - Install react-router-dom in your React app
npm i react-router-dom - Run an CLI
npx react-router-cli - Choose option
? What would you like to generate? (Use arrow keys)
❯ Base routing
Public/Private routing- Specify a path to your App file (ex.
/src/App.tsx)
PLEASE, DONT SPECIFY IT LIKE THIS:./src/App.tsx
Generated files
Base routing:
routingrouter-provider.tsxrouter-typings.tsroutes.tsrouting.tsx
Public/Private routing (routing with private routes):
routinglibPrivateRoutes.tsxPublicRoutes.tsx
router-provider.tsxrouter-typings.tsroutes.tsrouting.tsx
How to use
After generating base routing you need to do the following:
Base routing
- Define all routes in
routes.ts - Go to
Appand insert<Routing />component which was imported fromrouting.tsx
Public/Private routing
- Same things as in Base routing
- In
libdirectory specify condition on which private/public routes would work (for both components)
By default it's just variableisAuththat imitates that the user is logged in - In
PrivateRoutesin<Navigate to="" />specify the route to which user will be redirected if the user is not logged in - In
PublicRoutesin<Navigate to="" />specify the route to which the user will be redirected if the user is logged in