React-router: 2.1.0 breaks for server side rendering with code working in 2.0.0

Created on 11 Apr 2016  路  6Comments  路  Source: ReactTraining/react-router

Issue is simple to reproduce, see attached jsbin

const App = React.createClass({
  render() {
    return (
      <div />
    )
  }
})

var routes = (
  <ReactRouter.Router>
    <ReactRouter.Route path="*" component={App}/>
  </ReactRouter.Router>
)

ReactRouter.match({ routes: routes, location: "/test-url", basename: "/" }, (error, redirectLocation, renderProps) => {
  if (renderProps) {
    console.log("ok")
  }
  else {
    console.log("NOK")
  }
})

Works in 2.0.0 (outputs "ok")
Does not in 2.1.0 (outputs "NOK")

bug

Most helpful comment

@brotzky That's actually the correct way to push a location. We don't yet support relative URLs, so you should always use an absolute URL. We will get more strict about this in the future, but not in this release cycle.

All 6 comments

This is related to basename, so probably some recent changes for pattern matching.

location: "/test-url", basename: "/" ok in 2.0.0, not ok in 2.1.0

location: "/test-url", basename: "" ok in 2.0.0, ok in 2.1.0

location: "/lol/test-url", basename: "/lol/" ok in 2.0.0, not ok in 2.1.0

location: "/ol/test-url", basename: "/lol" ok in 2.0.0, ok in 2.1.0

It looks like 2.1.0 have issue with trailing slash on basename, where 2.0.0 was not.

Yeah, there was a mis-merge on my part in #3158 that didn't get reverted before we cut the release. I just put in a revert commit, so hold on 2.1 until 2.1.1 is out. Sorry for this mixup!

I just ran into this issue today when I ran some updates (but not server-side specific). @MoOx clarified the issue for me.
For anyone with the same problem this is what worked for me:

Original: browserHistory.push('login');

Fix: browserHistory.push('/login');

@brotzky That's actually the correct way to push a location. We don't yet support relative URLs, so you should always use an absolute URL. We will get more strict about this in the future, but not in this release cycle.

Thanks for the heads up, @timdorr

Fixed in 2.1.1. Sorry about that!

Was this page helpful?
0 / 5 - 0 ratings