File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed
Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -43,7 +43,8 @@ function handleNav(state, action) {
4343 link . origin != location . origin ||
4444 / ^ # / . test ( href ) ||
4545 ! / ^ ( _ ? s e l f ) ? $ / i. test ( link . target ) ||
46- ! isInScope ( href )
46+ ! isInScope ( href ) ||
47+ link . download
4748 ) {
4849 return state ;
4950 }
Original file line number Diff line number Diff line change @@ -819,6 +819,27 @@ describe('Router', () => {
819819 pushState . restore ( ) ;
820820 } ) ;
821821
822+ it ( 'should ignore clicks on download links' , async ( ) => {
823+ const downloadHref = URL . createObjectURL ( new Blob ( [ 'Hello World!' ] , { type : 'text/plain' } ) ) ;
824+
825+ render (
826+ < LocationProvider >
827+ < Router >
828+ < a href = { downloadHref } download = "hello-world.txt" > Download Me</ a >
829+ </ Router >
830+ < ShallowLocation />
831+ </ LocationProvider > ,
832+ scratch
833+ ) ;
834+
835+ scratch . querySelector ( 'a[download]' ) . click ( ) ;
836+ await sleep ( 1 ) ;
837+
838+ // If the router attempted to navigate, the page would throw a SecurityError
839+ // and the test would fail.
840+ expect ( true ) . to . equal ( true ) ;
841+ } ) ;
842+
822843 it ( 'should normalize children' , async ( ) => {
823844 const pushState = sinon . spy ( history , 'pushState' ) ;
824845 const Route = sinon . fake ( ( ) => < a href = "/foo#foo" > foo</ a > ) ;
You can’t perform that action at this time.
0 commit comments