larrymyers / react-mini-router

A minimal URL router for React.js
MIT License
282 stars 38 forks source link

Hash-bang urls in ^2.0.0 clears out some url information #57

Closed mrozbarry closed 7 years ago

mrozbarry commented 8 years ago

The company I work for is currently developing two applications, one that is using mini router ^1.7.0 and a new one that is using ^2.0.0.

With the 1.7.0 app, we are not using push state, and set our routes like:

routes: {
  '/': 'renderRoot',
  '/items': 'renderItems',
  '/items/:id': 'renderItem'
}

This works as expected, but in our new ^2.0.0 based app, it does not.

The new application is a static application that launches from app.html, so our router properties look like this:

ReactDOM.render(
  <AppRouter root='/app.html' />,
  document.getElementById('app')
)

We have wrapped our render like this:

render: function () {
  return (
    <div>
      { this.renderCurrentRoute() }
    </div>
  )
}

But when we specify a url in a link, the router does not catch it and removes app.html#! from our url, which breaks our application. Furthermore, we added a notFound: function (path) {} method, which detects all of our urls to be wrong if the defined route starts with a backslash.

We did not have this behaviour in ^1.7.0 and were wondering if there was some sort of regression, or if this is a feature that isn't documented properly.

Thanks for any help.

mrozbarry commented 8 years ago

As a summary, with our new app, if our routes are like this:

routes: {
  'things': 'renderThings',
  'things/:id': 'renderThing'
}

And we hit the url http://project.com/app.html#!/things, it works, but if our routes look like this:

routes: {
  '/things': 'renderThings',
  '/things/:id': 'renderThing'
}

Hitting the same url from above does not work, and calls notFound('/things').

cedmax commented 7 years ago

Hi @mrozbarry, sorry it took us a bit to get back to you, I'm helping Larry triaging the issues. I would say it's expected for version 2.0 not to be backward compatible with version 1.7, hence I'm closing this. Feel free to open a new issue if I missed something and the problem is still relevant to you.