redux-tiny-router icon indicating copy to clipboard operation
redux-tiny-router copied to clipboard

set and setRoutes from within component

Open gausie opened this issue 9 years ago • 1 comments

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?

gausie avatar Nov 03 '15 17:11 gausie

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.

gausie avatar Nov 04 '15 10:11 gausie