如何在ClojureScript/Reagent中动态更改页面标题和描述 [英] How to dynamically change page title and description in ClojureScript / Reagent

查看:117
本文介绍了如何在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 和<一个href ="https://github.com/gaearon/react-side-effect" rel ="nofollow noreferrer">反应-副作用,可以将其转换为试剂成分.但是,这种处理副作用的方法似乎很简单,可以在纯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,而是使用了类似的双向路由器silkre-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")

这篇关于如何在ClojureScript/Reagent中动态更改页面标题和描述的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆