React-sound soundmanager 不适用于 useHistory 钩子

时间:2021-06-18 19:17:31

标签: javascript reactjs react-router react-hooks html5-audio

"react-sound": "^1.2.0"

https://github.com/leoasis/react-sound

React-sound 是一个加载音频源的声音管理器。使用 react-router-dom 可以正常播放音频。使用

时音频不会暂停或关闭

但是使用 goBack() 钩子中的 goForward()useHistory 会在无意中停止音频播放,即使它似乎没有重新加载/重置页面。它的行为不像另一个浏览器路由器

<div className={style.BackForward}>
   <button onClick={() => { history.goBack() }} className={style.Icon}><FontAwesomeIcon icon={faChevronLeft} /></button>
   <button onClick={() => { history.goForward() }} className={style.Icon}><FontAwesomeIcon icon={faChevronRight} /></button>
</div>

点击后控制台日志是

soundmanager2.js:1307 sound0: Destruct
soundmanager2.js:1307 sound0: Removing event listeners
soundmanager2.js:1307 sound0: stop()
soundmanager2.js:1307 sound0: unload()

同样,我也不希望 history.push() 停止 react-audio 播放

0 个答案:

没有答案