"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 播放