I am trying to find an example of using a reactive router through the javascript API, but still could not find anything.
My goal is to use a reactive router with reagent and clojurescript. Therefore, if someone got this job (even with Ohm), I would be grateful for pushing in the right direction. Otherwise, only a simple javascript example without JSX will be useful.
Edit 1 - Get closer to the solution
Thanks to @FakeRainBrigand for helping me translate JSX into plain JS.
Here is React.js version 0.11.2 (this is what the current Reagent version uses - 0.4.3).
Routes({location: "history"}, Route({name: "app", path: "/", handler: App}, Route({name: "inbox", handler: Inbox}), Route({name: "calendar", handler: "{Calendar}"})))
Tip. You can perform the JSX-> JS conversion using JSXTransformer.js for your version of React. Just add it to your page and use the browser developer console to execute JSXTransformer.transform('/** @jsx React.DOM */<Route location="history">...</Route>').code
Here is the version of Clojurescript:
(ns mytest.core (:require [reagent.core :as reagent :refer [atom]]) (defn home [] [:div [:h1 "Home Component Placeholder"]]) (defn info [] [:div [:h1 "Info Component Placeholder"]]) (defn build-component [comp] (reagent/as-component (if (fn? comp) (comp) comp))) (defn react-router [] (js/ReactRouter.Routes
Unfortunately, the default Reagent components do not appear to be “standard” React components, in this React.isValidClass(myReagentComponent) === false . So all that remains is to figure out how to generate the components in the form that passes this test. I have a stack overflow question posted for this.
reactjs react-router clojurescript reagent
erikcw
source share