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.
2
Answers
I’m not using
bidi
, but a similar bidirectional routersilk
together withre-frame
. For every page change, we trigger a:set-current-route
event which will be handled centrally.The handler for
:set-current-route
will thenI am also not using
bidi
, but here is the solution I came up with for updating the HTML document title usingreitit
inreagent
. I call this function from my main route-wrapping component’s:component-did-update
: