paypal / react-engine

a composite render engine for universal (isomorphic) express apps to render both plain react views and react-router views
Apache License 2.0
1.45k stars 130 forks source link

Allow consumers to override history object #126

Open pklicnik opened 8 years ago

pklicnik commented 8 years ago

Since react-router 3.0, a history object is automatically created when the client is mounted:

var routerComponent = React.createElement(Router.Router, {
  createElement: function(Component, routerProps) {
    return React.createElement(Component, merge({}, props, routerProps));
  },

  routes: options.routes,
  history: routerHistory.createHistory()
});
ReactDOM.render(routerComponent, mountNode);

Consumers may need access to this history, so either allow users to provide a history object (via 'options' params) or provide a mechanism for consumers to access it.

dglozic commented 8 years ago

+1 this request

samsel commented 8 years ago

In v3.1.0, I've exposed the history object as the second argument in the function that we supply to the boot call. Do you have any specific use case wherin you would create the history object and give it to react-engine?

pklicnik commented 8 years ago

Thanks @samsel. We just need access to the history object, so the solution you've implemented works for me

epitaphmike commented 8 years ago

@samsel I am looking to create my own history object to use scroll-behavior. Right now I don't see a way to be able to do that. I currently have edited the client.js to make history: useScrollToTop(createBrowserHistory)(), but I'd prefer not to edit the library. Thoughts?

samsel commented 8 years ago

@epitaphmike are you looking to feed in your own history object?

epitaphmike commented 8 years ago

@samsel Yes. Unfortunately react-router currently doesn't support resetting of the scroll position of the page change or with anchored links. scroll-behavior handles these changes nicely. In order to maintain the history, I'd need to pass in the history object from scroll-behavior.

samsel commented 8 years ago

@epitaphmike I've added support for custom history object - https://github.com/paypal/react-engine/pull/145

epitaphmike commented 8 years ago

Thanks. Your change was exactly what I did locally. I guess I could have just submitted a pull request. I appreciate the update. Thank you again.

epitaphmike commented 8 years ago

It seems this has yet to be added to npm. Just wanted to give you a heads up. Thanks again

epitaphmike commented 8 years ago

@samsel Disregard my last comment. I see your pull request has yet to be merged as well. Thanks again

samsel commented 8 years ago

@epitaphmike its published now :)