【发布时间】:2015-03-06 13:57:49
【问题描述】:
如何根据更改后的 hash url 渲染 react 类?
这就是我的反应代码现在的样子:
module.exports = React.createClass { render: () ->
div {},
div {},
a { href: '#testhash' }, 'test link'
div {},
if (window.location.hash.substring(1) is 'testhash')
'this is a test'
else
'this is a sentence'
}
但它只能工作一次(即第一个网址是什么 - 有或没有主题标签)。
我怎样才能使 URL 哈希更改(单击 href)在单击时被拾取?
也就是说,然后test link被点击,页面应该是this is a test而不是this is a sentence。
有没有更简单的方法来做到这一点而无需添加状态值和按钮功能?
我需要使用 mixins 吗?
【问题讨论】:
标签: javascript coffeescript reactjs