Skip to content

Instantly share code, notes, and snippets.

@somecho
Created January 24, 2023 10:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save somecho/0801689de75e6587a54fd682b0347b08 to your computer and use it in GitHub Desktop.
Save somecho/0801689de75e6587a54fd682b0347b08 to your computer and use it in GitHub Desktop.
Very basic reagent + reitit front end routing template
(ns app.core
(:require [reagent.core :as r]
[reagent.dom :as rd]
[reitit.frontend :as rf]
[reitit.frontend.easy :as rfe]))
(defn about [] [:div "HELLO ABOUT ME"])
(defn another-view [] [:div "Another view"])
(defn home [] [:div "HOME"])
(def current-view (r/atom #'about))
(def router
(rf/router
[["/" {:name ::home
:view #'home}]
["/about" {:name ::about
:view #'about}]
["/another" {:name ::another
:view #'another-view}]]))
(rfe/start!
router
(fn [m]
(reset! current-view (get-in m [:data :view])))
{:use-fragment false})
(defn app []
[:div
[:div "HELLO WORLD"]
[:a {:href (rfe/href ::home)} "Home"]
[:a {:href (rfe/href ::about)} "About"]
[:a {:href (rfe/href ::another)} "Another"]
[@current-view]])
(rd/render [app] (.getElementById js/document "app"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment