redux-tiny-router
redux-tiny-router copied to clipboard
set and setRoutes from within component
It would be great to be able to use setRoutes from within the component (constructor probably). I could then do this:
_getRoutes() {
return {
'/': <SomeComponent />,
'/users/*': <SomeOtherComponent>,
}
}
constructor() {
super();
utils.setRoutes(Object.keys(this._getRoutes()));
}
And then later something like const component = this._getRoutes(this.props.router.src)
to choose the component.
However, it seems i can only do it externally to the class. Is this fixable?
For the moment, I have done this by adding a static getRoutes
function to the class, and then calling utils.setRoutes(Object.keys(App.getRoutes()));
at the bottom of the file.