diff --git a/src/scrollchor.jsx b/src/scrollchor.jsx index f0e1cb3..2705976 100644 --- a/src/scrollchor.jsx +++ b/src/scrollchor.jsx @@ -40,8 +40,11 @@ export default class Scrollchor extends React.Component { this._beforeAnimate(event); event && event.preventDefault(); const id = animateScroll(this._to, this._animate); - this._disableHistory || updateHistory(id); - this._afterAnimate(event); + + if (id) { + this._disableHistory || updateHistory(id); + this._afterAnimate(event); + } } componentWillReceiveProps (props) { diff --git a/src/utils.js b/src/utils.js index 99291b2..94beef0 100644 --- a/src/utils.js +++ b/src/utils.js @@ -5,6 +5,10 @@ export function animateScroll (id, animate) { const element = id ? document.getElementById(id) : document.body; warning(element, `Cannot find element: #${id}`); + if (!element) { + return null; + } + const { offset, duration, easing } = animate; const start = getScrollTop(); const to = getOffsetTop(element) + offset;