Fork me on GitHub
#reitit
<
2019-05-09
>
joshkh18:05:37

i'm using reitit.frontend.easy like so:

(rfe/start!
  (rf/router routes)
  (fn [route] ...))
and in another namespace i'd like to do the equivalent:
(r/match-by-name router ::order {:id 2})
but i don't have a handle on the router passed to rfe/start!. given that RFE is stateful, can the router be referenced somehow, or do i need to def the result of rf/router on my own?

valtteri18:05:13

At least I’m defing the router

valtteri18:05:48

AFAIK nothing in rfe is exposing ref to the router

joshkh18:05:28

i think you're right. i took a look through the source code but wasn't sure if the router was stored in another namespace.

joshkh18:05:40

thanks for the help!

valtteri19:05:48

Heh, actually you can get the router like this (:router @rfe/history)

joshkh19:05:23

aahhh. i wasn't sure if the history atom was the same as the result of calling rf/router. cool.

valtteri19:05:47

rf/router creates a new router. rfe namespace manages the state for you. You pass in the router on rfe/start and it creates the history thing with the router.

valtteri19:05:43

It’s probably just a matter of taste whether you want to def the router your self or access it through the derefed history object. 🙂

joshkh19:05:46

definitely 🙂

joshkh18:05:33

cool, i'm fine with that 🙂 just wasn't sure if there was a "batteries included" reitit.frontend.easy version of r/match-by-name that worked like rfe/href

valtteri19:05:47

It could be probably implemented quite trivially

joshkh19:05:05

for sure. i'm just partial to reducing my defs.

joshkh19:05:43

on to my next question! when using rfe/href is there a way to replace the current history rather than push onto it? i understand that rfe has different functions for push vs replace, but i'd like to define that when building a href

juhoteperi19:05:59

@joshkh Currently, no. It could be implemented for HTML5 router, e.g. by reading some data- attribute in a which would change the call here: https://github.com/metosin/reitit/blob/master/modules/reitit-frontend/src/reitit/frontend/history.cljs#L106 BUT I don't think this makes sense, href is used when user clicks an anchor, and clicking anchors should always push the new state to history.

joshkh19:05:04

that's sound logic, and thanks for the details. i'm just being lazy because i (think i remember?) reading that on-click isn't compatible with some mobile platforms that otherwise require a tap event.

juhoteperi19:05:27

If you really need this, you can easily call rfe/replace-state in :on-click handler

juhoteperi19:05:29

Or if you can find example of "popular" JS routing library that provides this for anchors, I could revise my opinion

PB19:05:54

Hi all. I am currently trying to send an arraybuffer to an api stood up by reitit. Obviously, it is barfing while trying to parse the params in body. What is the correct way to deal with this??