Skip to content
This repository has been archived by the owner on Jan 22, 2020. It is now read-only.

Allow consumers to override history object #126

Open
pklicnik opened this issue Jan 19, 2016 · 11 comments
Open

Allow consumers to override history object #126

pklicnik opened this issue Jan 19, 2016 · 11 comments

Comments

@pklicnik
Copy link

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
Copy link

dglozic commented Jan 20, 2016

+1 this request

@samsel
Copy link
Contributor

samsel commented Jan 26, 2016

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
Copy link
Author

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

@epitaphmike
Copy link

@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
Copy link
Contributor

samsel commented Mar 26, 2016

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

@epitaphmike
Copy link

@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
Copy link
Contributor

samsel commented Mar 28, 2016

@epitaphmike I've added support for custom history object - #145

@epitaphmike
Copy link

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
Copy link

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

@epitaphmike
Copy link

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

@samsel
Copy link
Contributor

samsel commented Mar 29, 2016

@epitaphmike its published now :)

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

No branches or pull requests

4 participants