Skip to content

Commit

Permalink
Merge pull request #11 from CloudPower97/fix/subdir-scrollspy
Browse files Browse the repository at this point in the history
fix: add support for subdirectory served app
  • Loading branch information
CloudPower97 committed Dec 3, 2018
2 parents 9d09a2e + 53e8140 commit a3e532c
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Scrollspy.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,16 @@ export default class Scrollspy extends Component {

getElements = () => {
const { items } = this.props
const { pathname } = window.location

this.setState(
{
elementsToSpy: items.map(item => document.getElementById(item)).filter(item => item),
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),
},
Expand Down

0 comments on commit a3e532c

Please sign in to comment.