kitze / mobx-router

A simple router for MobX + React apps
509 stars 66 forks source link

Adding support for html5history:false #7

Closed RainerAtSpirit closed 8 years ago

RainerAtSpirit commented 8 years ago

This should address scenarios like https://github.com/kitze/mobx-router/issues/5 where the underlying server doesn't support deep linking.

Here's a hardcoded mockup that sets it to false and updates autorun.

...
const createDirectorRouter = (views, store) => {
  new Router({
    ...viewsForDirector(views, store)
  }).configure({
    html5history: false
  }).init('/');
};

const startRouter = (views, store) => {
  //create director configuration
  createDirectorRouter(views, store);

  //autorun and watch for path changes
  autorun(() => {
    const {currentPath} = store.router;
    const hash = `#${path}`;
    if (path !== window.location.hash) {
      window.history.pushState(null, null, hash);
    }
  });
};

export default startRouter;
kitze commented 8 years ago

Just closed #5 , it was a problem with the hosting of the examples. Deep links should work perfectly fine.

RainerAtSpirit commented 8 years ago

I'm aware of the fact that #5 was an issue with the server :). It would be still great having the option to use hash-history. Shouldn't be too hard to implement by allowing a third optional {html5history: true|false (default)} argument.

RainerAtSpirit commented 8 years ago

Forgot to add I can send a PR for that if you think that supporting hash-history is a useful capability for mobx-router.

TimDaub commented 5 years ago

Has this been considered? I'd like to host on github pages and the only way I see paths like e.g. /a/b/0 working is with hash-history.

I can submit a PR if necessary.

TimDaub commented 5 years ago

I added this via: #73