Fork me on GitHub
#re-frame
<
2021-11-05
>
ns17:11:02

Beginner re-frame + bidi router question: How do I navigate user to different route after successfully submitting post? In routes.cljs I see "dispatch" and "navigate" (which I assume are used for this task) but I am not sure how to use them.

p-himik17:11:01

What is routes.cljs, where does it come from? But in general, bidi is a router - it matches URLs to IDs/parameters and vice versa. Navigating to specific URLs is an independent concept. E.g. kee-frame uses https://github.com/venantius/accountant for that.

ns17:11:32

routes.cljs is a file that was automatically setup for me when using bidi in combinatio with re-frame and where routes for my app are defined. My problem is I don't know how to redirect user to one of those routes after, say, successful post submission to backend api.

p-himik19:11:25

So that's an artifact created by the particular template you used - not really related to bidi or re-frame themselves. > I don't know how to redirect user to one of those routes You need to have a URL - bidi can help with that. You also need to set the current browser location to that URL without a page refresh - bidi cannot help there. As I mentioned, there are other libraries for that, like accountant. Or you can use HTML5 history API yourself, without any libraries. You can also look at kee-frame - the library has a decent amount of things covered, including being able to redirect users to some page with an event/effect.

ns22:11:16

Thanks, you sent me on the right path and I think I got it working. I installed re-frame with bidi + pushy and it came with a ::navigate event which is just a wrapper around pushy/set-token which sets html5 history (if I understood things right). But yeah, like I said, it seems to work. Thanks!

šŸ‘ 1
Michaƫl Salihi08:11:20

reitit support HTML5 history api out of the box too. See this example which is great: https://github.com/metosin/reitit/tree/master/examples/frontend-re-frame