From 53e8140bbd71c49763b632ee6c9ffbab5b38be2c Mon Sep 17 00:00:00 2001 From: Claudio Cortese Date: Mon, 3 Dec 2018 17:16:14 +0100 Subject: [PATCH] fix: add support for subdirectory served app Closes #10 --- src/Scrollspy.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Scrollspy.js b/src/Scrollspy.js index b127225..bbb4794 100644 --- a/src/Scrollspy.js +++ b/src/Scrollspy.js @@ -40,6 +40,7 @@ export default class Scrollspy extends Component { getElements = () => { const { items } = this.props + const { pathname } = window.location this.setState( { @@ -47,8 +48,8 @@ export default class Scrollspy extends Component { navItems: items .map( item => - document.querySelector(`[href="#${item}"]`) || - document.querySelector(`[href="/#${item}"]`) + document.querySelector(`[href="${pathname}#${item}"]`) || + document.querySelector(`[href="${pathname}/#${item}"]`) ) .filter(item => item), },