Created
January 24, 2023 10:52
-
-
Save somecho/0801689de75e6587a54fd682b0347b08 to your computer and use it in GitHub Desktop.
Very basic reagent + reitit front end routing template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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