Is there a simple way to change document title and description (or other [:html [:head [:meta
tags) from ClojureScript Reagent application? For example on every bidi
route match change the title and description to match the new page content.
Preferably this should work without using js/window
so that the same code can be used in a browser as well as in server isomorphic pre-rendering (which I need for SEO).
In the JavaScript/React world there are react-document-meta and react-side-effect which can probably be converted to Reagent components. But this way of handling side effects seems like a hack and probably simpler solution can be done in pure ClojureScript.
I'm not using bidi
, but a similar bidirectional router silk
together with re-frame
. For every page change, we trigger a :set-current-route
event which will be handled centrally.
The handler for :set-current-route
will then
(set! (.-title js/document) "dynamic title")
来源:https://stackoverflow.com/questions/44975192/how-to-dynamically-change-page-title-and-description-in-clojurescript-reagent