如何在ClojureScript/Reagent中动态更改页面标题和描述
是否有一种简单的方法可以从ClojureScript Reagent应用程序更改文档标题和说明(或其他[:html [:head [:meta
标记)?例如,在每个bidi
路由匹配项上,更改标题和描述以匹配新页面内容.
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.
最好在不使用js/window
的情况下就可以正常工作,以便可以在浏览器以及服务器同构预渲染(我需要SEO)中使用相同的代码.
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).
在JavaScript/React世界中,有 react-document-meta 和反应-副作用,可以将其转换为试剂成分.但是,这种处理副作用的方法似乎很简单,可以在纯ClojureScript中完成可能更简单的解决方案.
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.
我没有使用bidi
,而是使用了类似的双向路由器silk
和re-frame
.对于每次页面更改,我们都会触发一个:set-current-route
事件,该事件将集中处理.
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.
然后:set-current-route
的处理程序将
(set! (.-title js/document) "dynamic title")