mirror icon indicating copy to clipboard operation
mirror copied to clipboard

Opt out of React-Router v4

Open ShMcK opened this issue 8 years ago • 3 comments

There should be a way to opt out of using react-router v4.

This would be especially useful for mobile. Currently, Mirror is not compatible with "react-native" due to the dependency on react-dom. Opting into react-router-native isn't much better, as it's not currently the most popular routing option.

As a suggestion, using dynamic imports, would make it possible to opt out of using the router.

// default to true
options.useRouter = options.useRouter || true

if (options.useRouter) {
  // dynamic import (may require Webpack plugin)
  import('./router')
}

ShMcK avatar Sep 10 '17 23:09 ShMcK

I've done some experimenting with opting out of React Router in Mirror on this project branch. It's not complete, and may not be necessary.

I see a few options now for dealing with the router:

  1. Continue to not support other routers or react-native
  2. Load all router imports through mirrorx/router, a submodule. Then dynamically import it unless an option of noRouter is specified.
  3. Create a separate mirrorx-router package, which can be configured and setup

Both 2 & 3 would create breaking changes, though easy to fix.

ShMcK avatar Sep 12 '17 06:09 ShMcK

I would recommend mirrorx/router as a submodule, what's your opinion?

llh911001 avatar Sep 12 '17 09:09 llh911001

I think think a submodule makes the most sense.

Also the same design of dva/router.

Dva also recently created multiple different router packages with the 2.0.1 release, including "dva/no-router". I think this is a bit much, as its not really necessary to load another package if you're not using the router.

ShMcK avatar Sep 12 '17 14:09 ShMcK