reactjs/react-router-redux

push() replaces url

anushkadoyan opened this issue · 4 comments

I'm trying to use push() to push to the url and update my route. However, push is replacing my url with the specified url in push().

For example:
current url = foo.bar/hello
push('/world')
expected url = foo.bar/hello/world
actual url = foo.bar/world

You have to push the full URL. push('/hello/world')

What's the point of push in that case? shouldn't push be adding to the stack instead of replacing the full path?

It's adding to the stack. That's essentially an array of all the URLs you've pushed onto it. The stack isn't the current URL broken up by slashes. You're thinking of URL segments.

Here's how the DOM history works. Check it out: https://developer.mozilla.org/en-US/docs/Web/API/History_API#Adding_and_modifying_history_entries

Okay, thanks!