diff --git a/src/router.js b/src/router.js index ac5d5cc..4926f33 100644 --- a/src/router.js +++ b/src/router.js @@ -16,7 +16,7 @@ const UPDATE = (state, url) => { return state; } - const link = url.target.closest('a[href]'), + const link = url.composedPath().find(el => el.nodeName == 'A' && el.href), href = link && link.getAttribute('href'); if ( !link || diff --git a/test/router.test.js b/test/router.test.js index 984699f..e091a2d 100644 --- a/test/router.test.js +++ b/test/router.test.js @@ -927,6 +927,41 @@ describe('Router', () => { await sleep(10); expect(scratch).to.have.property('textContent', 'data'); }); + + it('should intercept clicks on links inside open shadow DOM', async () => { + const shadowlink = document.createElement('a'); + shadowlink.href = '/shadow'; + shadowlink.textContent = 'Shadow Link'; + shadowlink.addEventListener('click', e => e.preventDefault()); + + const attachShadow = (el) => { + if (!el || el.shadowRoot) return; + const shadowroot = el.attachShadow({ mode: 'open' }); + shadowroot.appendChild(shadowlink); + } + + const Home = sinon.fake(() =>
); + const Shadow = sinon.fake(() =>