Simple react router than can get you up and running in 5 minutes
npm install mr-react-router --save
oryarn install mr-react-router
- Include the router by importing it ie:
import Router from 'mr-react-router'
- Declare routes and pass the to the router:
import Main from './main' // main is a component you define
const isLoggedIn = () => {
// any logic that returns true or false. True will return trigger the redirect
return true
}
const routes = [{
path: '/',
component: Main,
check: isLoggedIn,
redirect: '/login',
}]
const App = () => {
return (
<Provider store={store}>
<Router routes={routes} />
</Provider>
)
}
Almost anyone can understand this type of router and it's flexible for 90% of the use cases. I'll be adding the following in the future:
- Grouped route checks
- React hooks
- Link to helpers
- Named routes
- Better async support