Skip to content

Commit a3e532c

Browse files
authored
Merge pull request #11 from CloudPower97/fix/subdir-scrollspy
fix: add support for subdirectory served app
2 parents 9d09a2e + 53e8140 commit a3e532c

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/Scrollspy.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,16 @@ export default class Scrollspy extends Component {
4040

4141
getElements = () => {
4242
const { items } = this.props
43+
const { pathname } = window.location
4344

4445
this.setState(
4546
{
4647
elementsToSpy: items.map(item => document.getElementById(item)).filter(item => item),
4748
navItems: items
4849
.map(
4950
item =>
50-
document.querySelector(`[href="#${item}"]`) ||
51-
document.querySelector(`[href="/#${item}"]`)
51+
document.querySelector(`[href="${pathname}#${item}"]`) ||
52+
document.querySelector(`[href="${pathname}/#${item}"]`)
5253
)
5354
.filter(item => item),
5455
},

0 commit comments

Comments
 (0)