Closed thunderkid closed 8 years ago
Yes and no.
I've personally always used Cherrytree in a "unidirectional data flowy way" and I'd probably recommend doing that. That is, you never update something in your app outside of the "transition > changes url > calls middleware > updates your app" loop. For example, if you click on a filter and want to update app state + url, you should transition, which will update url, which will call middleware, which should update the app.
Having said that, there might be use cases for updating URL that I haven't thought about and I'd be interested to here what your use case is.
You could try updating it directly via the location handler, which isn't something documented, but would work today:
router.location.setURL(url, {trigger: false})
router.location.replaceURL(url, {trigger: false})
(you can try running that code in console here: http://kidkarolis.github.io/cherrytree-redux-react-example)
Trigger false
here means location will just update URL and won't trigger events, which means cherrytree will not call middelwares. The only drawback of this that I can think of is that this will put the router into incosistent state where router.state
will still be representing the previous URL. But if that's not a problem for you - then it's all good. But if you use transition.prevRoutes
, that might cause issues. In the future, I'm interested in completely removing state
and prevRoutes
from the router making it stateless, which might solve this particular issue.
Is there currently a way to call transitionTo(url) silently, ie replacing the url in the browser without triggering any middleware? (Other libraries seem to provide this but I can't see it in the docs here.)