GithubHelp home page GithubHelp logo

Comments (5)

mjackson avatar mjackson commented on April 24, 2024

I modified the issue title because we don't have a listenAfter API.

Eh ... ok. I get it. But why are you rendering in listenBefore? That's your cue that "things might change, we're not sure yet". Seems much safer to run your code in the listen callback.

from history.

stevoland avatar stevoland commented on April 24, 2024

Apologies for the incorrect title.

You're right, what we're doing in listenBefore in this instance is a hack to maintain use case that was easily achieved with react-router v1.0.0-beta3.

I maintain that it's reasonable to expect a history API that offers a listenBefore hook to fire those callbacks on browser navigation regardless of whether a different listener is also registered. Disagree?

from history.

mjackson avatar mjackson commented on April 24, 2024

it's reasonable to expect a history API that offers a listenBefore hook to fire those callbacks on browser navigation regardless of whether a different listener is also registered

Ya, that's reasonable. But your use case is still invalid. I'd much prefer to drive further development with valid use cases instead of theory. If there's a good reason why you're using listenBefore instead of listen for rendering, I'd like to know.

EDIT: I should also say that I'm open to fixing this. Just want to know why you're using listenBefore instead of listen.

from history.

stevoland avatar stevoland commented on April 24, 2024

The linked project uses listenBefore instead of listen in order to fetch the data required for the next routes before the location bar is updated. You say this use case is invalid and I have agreed although I note that there are others who do want this use case: https://twitter.com/gpblv/status/650249197950738432

I didn't create this ticket to drive further development, just to address what I see is an issue with this project. I maintain that listenBefore handlers should always be called, although I don't have a real-world use case.

IMO the code should be changed or a warning added to the docs as neither of the examples here would work without a listen handler also added: https://github.com/rackt/history/blob/master/docs/ConfirmingNavigation.md

Like I say, let me know if you want a PR otherwise I'll close this issue.

from history.

mjackson avatar mjackson commented on April 24, 2024

You have a great point about the docs. Sure, let's make this change. A PR would be great, thanks for offering :)

In order to make this change you'll need to override listenBefore in both createBrowserHistory and createHashHistory. Currently, both of those implementations override listen to know when they need to setup/teardown DOM event listeners.

from history.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.