Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

History object throws an error when trying to createLocation server.js in beta4. #162

Closed
rynbyjn opened this issue Nov 9, 2015 · 4 comments
Assignees
Labels

Comments

@rynbyjn
Copy link

rynbyjn commented Nov 9, 2015

I am using redux-router with isomorphic-fetch server side and ran across an issue if you do not pass a createHistory object into reduxReactRouter({ routes: routes }) in a server.js file in beta4.

This is the error thrown within history:

TypeError: Cannot read property 'apply' of undefined
    at Object.createLocation (/node_modules/history/lib/useQueries.js:99:45)

Before beta4 passing the createHistory property was optional from redux-router/server and createLocation from the requested url just worked. The workaround that I am using is to just call reduxReactRouter({ routes: routes, createHistory: createHistory }) when composing the server store. Note that you can't use createBrowserHistory as it requires a DOM.

Might be nice to auto create a default history object on the server if one does not exist. Another option would be to pass in the location instead of just the url...

Instead of this:

  app.use((req, res) => {
    store.dispatch(match(req.url, (error, redirectLocation, routerState) => { 
      // do your rendering here
    }))
  })

You would use this (this is how react-router expects the location in their match method):

  import createLocation from 'history/lib/createLocation'
  app.use((req, res) => {
    const location = createLocation(req.url)
    store.dispatch(match(location, (error, redirectLocation, routerState) => { 
      // do your rendering here
    }))
  })
@twDuke
Copy link

twDuke commented Nov 16, 2015

Confused me for several hours. Please document or fix.

@Scarysize Scarysize self-assigned this Nov 16, 2015
@xcatliu
Copy link

xcatliu commented Nov 19, 2015

Related issue: #159

@xcatliu
Copy link

xcatliu commented Nov 19, 2015

I followed a server rendering example, then met this issue.
Just relate them to help other people.
https://github.com/rackt/redux-router/pull/95/files#diff-2762483ac89ccfaf73745a0c7698af36R54

@Scarysize
Copy link
Contributor

The current server-rendering example should clarify what history function to use.

https://github.com/acdlite/redux-router/blob/master/examples/server-rendering/server.js#L11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants