Fork me on GitHub
#reagent
<
2023-10-13
>
Lispyyy06:10:51

how to switch the route in reagent project? i use lein new reagent app to create an app, i want to create button which will send a request to backend and switch route into route :app after it, how should i do?

Lispyyy06:10:41

(defn jump [to]
  (session/update! :route
                   merge
                   {:current-page to}))
this one will change the app layout, but the url in location won't change, how should i to change the locationL

Mario Trost07:10:08

Supposing :app is located at /app :

(defn jump [to]
  (session/update! :route
                   merge
                   {:current-page to})
  (.pushState (.-history js/window) nil "" "/app"))
This changes the URL to (.pushState (.-history js/window) nil "" "/app") should probably be done in the side-effecty function session/update! I recommend a client-side routing solution like reitit if you have a more complex app.

❤️ 1
Lispyyy07:10:11

thank you, it work!!!