0.0.27 • Published 4 years ago
react-route-generator v0.0.27
react-route-generator
This is the MVP of the code generator for route types that are written in https://github.com/pillarjs/path-to-regexp which is what react-router uses internally.
The generated types can be used to type generic Route
component props
Install
$ yarn add react-route-generator
Or
$ npm i react-route-generator
Create config
Add routegen.yml
to project root. Example:
apps:
client:
routes:
login: /app/login
signup: /app/signup
logout: /app/logout
me: /app/me
routingType: ReactRouter
destinationDir: client/src/routes
client-seo:
routes:
home: /
routingType: NextJS
destinationDir: client-seo/src/routes
# Use on of these options below if you want to custom how Link is created
reactRouterLinkCreatorPath: src/common/ui/createCustomReactRouterLink
nextJSLinkCreatorPath?: src/common/ui/createCustomNextJSLink
defaultLinkCreatorPath?: src/common/ui/createDefaultLink
Generate
$ yarn routegen
Or
$ npx routegen
Developing
Build it!
We need to build from TS -> JS to be able to run the generator. For the changes to reflect, after making changes in src
, run the following:
$ yarn run build
Run it!
$ yarn run generate
Or Do it all in one command!
$ yarn run test:cli
How it works
- Reads in the config
- Go through each "app"
- Look at the routes it needs to generate and destination folder
- Generate each route into its own file in the destination folder ( this helps codesplitting )
- The files are generated into
tests/output
folder for now
TODO
- Bring over
createRoute
function which uses the generated types to generate the route objects - Break
index.ts
into smaller files - Handle inter app routing
- Handle NextJS routing
- Add yaml file for config
- Make this CLI
- Publish
- Generate route / link creators
- Generate url function needs to take URL query. Maybe pass this into each
createLink
as a function so route & link always have the same function. - Tests
- Set up CI
- Clean up
0.0.20
4 years ago
0.0.21
4 years ago
0.0.22
4 years ago
0.0.23
4 years ago
0.0.24
4 years ago
0.0.25
4 years ago
0.0.19
4 years ago
0.0.26
4 years ago
0.0.27
4 years ago
0.0.17
4 years ago
0.0.18
4 years ago
0.0.16
4 years ago
0.0.15
4 years ago
0.0.14
4 years ago
0.0.12
4 years ago
0.0.13
4 years ago
0.0.11
4 years ago
0.0.10
4 years ago
0.0.9
4 years ago
0.0.8
4 years ago
0.0.7
4 years ago
0.0.6
4 years ago
0.0.5
4 years ago
0.0.4
4 years ago
0.0.3
4 years ago
0.0.2
4 years ago
0.0.1
4 years ago