@@ -1476,14 +1476,22 @@ describe("a router", () => {
14761476 } ) ;
14771477 } ) ;
14781478
1479- it ( "does not run loaders on hash change only navigations" , async ( ) => {
1479+ it ( "does not run loaders on hash change only navigations (no hash -> hash) " , async ( ) => {
14801480 let t = initializeTmTest ( ) ;
14811481 expect ( t . router . state . loaderData ) . toMatchObject ( { root : "ROOT" } ) ;
14821482 let A = await t . navigate ( "/#bar" ) ;
14831483 expect ( A . loaders . root . stub . mock . calls . length ) . toBe ( 0 ) ;
14841484 expect ( t . router . state . loaderData ) . toMatchObject ( { root : "ROOT" } ) ;
14851485 } ) ;
14861486
1487+ it ( "does not run loaders on hash change only navigations (hash -> new hash)" , async ( ) => {
1488+ let t = initializeTmTest ( { url : "/#foo" } ) ;
1489+ expect ( t . router . state . loaderData ) . toMatchObject ( { root : "ROOT" } ) ;
1490+ let A = await t . navigate ( "/#bar" ) ;
1491+ expect ( A . loaders . root . stub . mock . calls . length ) . toBe ( 0 ) ;
1492+ expect ( t . router . state . loaderData ) . toMatchObject ( { root : "ROOT" } ) ;
1493+ } ) ;
1494+
14871495 it ( "does not run loaders on same-hash navigations" , async ( ) => {
14881496 let t = initializeTmTest ( { url : "/#bar" } ) ;
14891497 expect ( t . router . state . loaderData ) . toMatchObject ( { root : "ROOT" } ) ;
@@ -5245,6 +5253,47 @@ describe("a router", () => {
52455253 router . dispose ( ) ;
52465254 } ) ;
52475255
5256+ it ( "kicks off initial data load when hash is present" , async ( ) => {
5257+ let loaderDfd = createDeferred ( ) ;
5258+ let loaderSpy = jest . fn ( ( ) => loaderDfd . promise ) ;
5259+ let router = createRouter ( {
5260+ history : createMemoryHistory ( { initialEntries : [ "/#hash" ] } ) ,
5261+ routes : [
5262+ {
5263+ path : "/" ,
5264+ loader : loaderSpy ,
5265+ } ,
5266+ ] ,
5267+ } ) ;
5268+ router . initialize ( ) ;
5269+
5270+ expect ( console . warn ) . not . toHaveBeenCalled ( ) ;
5271+ expect ( loaderSpy . mock . calls . length ) . toBe ( 1 ) ;
5272+ expect ( router . state ) . toMatchObject ( {
5273+ historyAction : "POP" ,
5274+ location : expect . objectContaining ( { pathname : "/" , hash : "#hash" } ) ,
5275+ initialized : false ,
5276+ navigation : {
5277+ state : "loading" ,
5278+ location : { pathname : "/" , hash : "#hash" } ,
5279+ } ,
5280+ } ) ;
5281+ expect ( router . state . loaderData ) . toEqual ( { } ) ;
5282+
5283+ await loaderDfd . resolve ( "DATA" ) ;
5284+ expect ( router . state ) . toMatchObject ( {
5285+ historyAction : "POP" ,
5286+ location : expect . objectContaining ( { pathname : "/" , hash : "#hash" } ) ,
5287+ initialized : true ,
5288+ navigation : IDLE_NAVIGATION ,
5289+ loaderData : {
5290+ "0" : "DATA" ,
5291+ } ,
5292+ } ) ;
5293+
5294+ router . dispose ( ) ;
5295+ } ) ;
5296+
52485297 it ( "executes loaders on push navigations" , async ( ) => {
52495298 let t = setup ( {
52505299 routes : TASK_ROUTES ,
0 commit comments