Make a Router from mobx-state-tree model !
TODO
TODO
yarn add k-mst-router
npm i --save k-mst-router
- Import the Model from k-mst-router:
import Router from 'k-mst-router'
- Use it to one of your model, and initialize it with a
preProcessSnapshot
:
import { types } from 'mobx-state-tree'
import Router from 'k-mst-router'
export default types
.model({
router: Router,
})
.named('Store')
.preProcessSnapshot(snapshot => ({
...snapshot,
router: {
screens: [
{
name: 'list',
path: '/',
},
{
name: 'new',
path: '/new',
},
{
name: 'authentication',
path: '/login',
},
{
name: 'edit',
path: '/contacts/:id',
}
],
},
}))
- Change routes with
go
action:store.router.go('new')
- It supports parameters:
store.router.go('edit', { id: 3 })
uni rakun is created by two passionate french developers.
Do you want to contact them ? Go to their website
Guillaume CRESPEL | Fabien JUIF |