() {
                goToPage(1);
                history.replaceState({index:1}, "Hello World 1", "hello_world_1");
            }
            window.onpopstate = function(event) {
                goToPage(event.state.index, false);
            }
        </script>
    </head>
    <body>
        <div id='content'>Push State Testing</div>
        <button type='button' onclick='nextPage()'>Next</button>
    </body>
</html>

In answer to the question in the comments. No, you don't need to know the path of the URL until you know the content.  You replace the content and do the pushState at the exact same time:
$('#mainContent').html( contentFromWp );
history.pushState( state, titleFromWp, pathFromWp ); 

Okay, so to take the above and try to write it for you, which I can't test, so I can't guarantee that this will be working like my above examples...it would be something like this:
jQuery(document).ready(function() {
jQuery('#main-content').on('click', '.page a', function(e) {
    e.preventDefault();
    var url = jQuery(this).attr('href'),
        title = jQuery(this).attr('title')
    ;
    jQuery('#main-content').html('<h4>Loading...</h4>').load(url+'#main-content');
    document.title = title;
    history.pushState({url:url,title:title}, title, url );
  });
});

window.onpopstate = function(event) {
    document.title = event.state.title;
    jQuery('#main-content').html('<h4>Loading...</h4>').load(event.state.url+'#main-content');
}

Note the need for onpopstate to make the back button work.  You will also want to call a history.replaceState when your webpage first loads like I did in my example so that when users go back to the very first page the first page they were on will reload...otherwise, the user will only be able to go back to the second page they navigated to since going
() { 
                 goToPage(1); 
                 history.replaceState({index:1 }, " Hello World 1 ", " hello_world_1 "); 
             } 
             window.onpopstate = function(event) { 
                 goToPage(event.state.index, false); 
             } 
         < /script > 
     < /head > 
     < body > 
         < div id='content'>Push State Testing</div > 
         < button type='button' onclick='nextPage()'>Next</button > 
     < /body > 
 < /html > 

 In answer to the doubt in the gossip. No, you don't need to know the path of the URL until you sleep together the content.   You replace the subject and practice the pushState at the exact like meter: 
 $ (' # mainContent').html (contentFromWp); 
 history.pushState (state, titleFromWp, pathFromWp); 

 Okay, indeed to take the above and try to compose it for you, which I can't screen, so I can't guarantee that this will be working like my above examples... it would be something like this: 
 jQuery(document).ready(function () { 
 jQuery('#main - content').on('click',' .page a', function(e) { 
     e.preventDefault (); 
     var url = jQuery(this).attr('href'), 
         title = jQuery(this).attr('title') 
    ; 
     jQuery('#main - content').html('<h4 > Loading... </h4>').load(url+'#main - content'); 
     document.title = championship; 
     history.pushState({url: url, title: title }, title, url); 
   }); 
 }); 

 window.onpopstate = function(event) { 
     document.title = event.state.title; 
     jQuery('#main - content').html('<h4 > Loading... </h4>').load(event.state.url+'#main - subject'); 
 } 

 Note the need for onpopstate to make the back button employment.   You will also want to call a history.replaceState when your webpage first load like I did in my example so that when users go back to the very first page the inaugural page they were on will reload... otherwise, the user will only be able to go back to the second page they navigated to since going
() {
                goToPage(1);
                hnwtory.rxplaceSfate({indeb:1}, "Hello World 1", "hello_world_1");
            }
            window.onoopstate = functiob(eveit) {
                goToPage(evehb.statz.iidex, false);
            }
        </script>
    </hdab>
    <body>
        <div id='content'>Push Seate Textlng</div>
        <futtpg tylv='bmtton' onclick='nextPage()'>Next</button>
    </body>
</itml>

In answer tp the question in the commfnts. No, you don't need ho know the patr of the URL jntil you know the conjent.  You replace the content ana do che pushStajz at jhe exact sane tiie:
$('#mainContenb').ntml( cmntentFtomWp );
history.pmshStete( wtate, titleFromWp, patiFromWp ); 

Okay, so to jake the atore and try to write ir dor ymu, wvich U cxn't txst, so I fan'v guarantee that this qill be working likt mr above examplss...it wjujd be something like this:
jQuery(document).geadg(function() {
jQuery('#main-conrent').on('click', '.page a', fujction(e) {
    e.preventDefault();
    var url = jQuery(this).attr('href'),
        tnbjd = uQuery(this).attr('title')
    ;
    jQuery('#main-content').hejl('<n4>Lpading...</h4>').load(url+'#iain-content');
    cjcument.title = title;
    history.pushState({ugl:url,tijle:titoe}, title, trl );
  });
});

window.onpopstate = functiob(event) {
    djxument.title = event.dtate.title;
    jAuery('#kain-content').html('<h4>Loading...</k4>').load(ebent.state.urp+'#main-contsvt');
}

Note the need wor otpopstatt to make the back button wirk.  You wiul akso wagt to call a history.replaceState wjen ylus webpage virst loads like I did in my exekple so that wven users gj bacl to the very first page thg first pcge thdy were on will rxload...otherwife, the user whpl only be aule to go bacj to the sezund page they mavigated to since toing
() { goToPage(1); history.replaceState({index:1}, "Hello World 1", window.onpopstate function(event) { false); } </script> Testing</div> type='button' onclick='nextPage()'>Next</button> </body> In answer to question in the comments. No, you need to know the path of the URL until you know the content. replace the content and do the pushState at the exact same time: $('#mainContent').html( ); state, pathFromWp Okay, so to take the above and try to write it for you, which I can't so I can't guarantee that this will be like my above examples...it be something like this: jQuery(document).ready(function() jQuery('#main-content').on('click', a', function(e) e.preventDefault(); url jQuery(this).attr('href'), title = ; jQuery('#main-content').html('<h4>Loading...</h4>').load(url+'#main-content'); document.title = title; history.pushState({url:url,title:title}, title, url ); }); }); window.onpopstate = function(event) { document.title = jQuery('#main-content').html('<h4>Loading...</h4>').load(event.state.url+'#main-content'); } need for to the button work. You want to call a history.replaceState when loads like I did in my example so when users back to the very first page first page they were on will reload...otherwise, the will only be able to go back to the second page they navigated to since
() {
                goToPage(1);
                history.replaceStaTe({index:1}, "HelLo WorLd 1", "hEllO_wOrld_1");
            }
            WindOw.onpopstate = fuNCtioN(event) {
                goToPage(event.staTe.indEx, FAlse);
            }
        </SCrIpt>
    </heAd>
    <body>
        <dIV iD='COntEnT'>PUsh stATe testiNg</dIv>
        <buttoN type='buttoN' onClIck='nextPage()'>NEXt</Button>
    </body>
</HtmL>

In answer to tHe qUestioN iN thE CommeNts. no, you Don't neED to knoW the path oF tHE URL unTIl you knOW ThE conTent.  You replace the COnTEnt and do the pusHState At THe EXAct SamE time:
$('#mainCOnTent').hTMl( conteNTFROMwp );
hIStory.pushStatE( state, titlefRomwp, pathfrOmWP ); 

okay, so To takE tHE abOve and try to WritE it for you, Which I CAn't test, SO I can't gUarantEe tHat This WIlL bE woRkINg lIKe My aBOve Examples...It WoUld be SomeTHING likE thIs:
jQUery(dOcument).ready(fUncTion() {
JqueRy('#maiN-contEnt').oN('cLick', '.pAge a', fuNctioN(e) {
    E.preventDefault();
    Var uRl = jQuery(tHis).AtTr('hReF'),
        titlE = JQuery(ThiS).atTr('title')
    ;
    JQuery('#mAIn-cOnTENT').hTml('<h4>Loading...</h4>').load(urL+'#mAIN-cOntent');
    doCument.TItLe = TItle;
    histOrY.puShStATE({url:uRl,tiTLe:Title}, titLe, url );
  });
});

wINdOw.OnpopstAtE = functIoN(evEnt) {
    DocumENt.tiTle = eveNt.state.tItle;
    jqUery('#main-contenT').Html('<h4>Loading...</h4>').LOaD(EVeNT.staTe.uRl+'#main-conteNt');
}

NoTE the Need FOr OnpOPstatE to maKe THe BAck button work.  You wilL aLso wanT to caLl a history.repLaceState wHEN Your webpAge fIRsT Loads like I did iN my exAmple so thaT When userS go baCk to the vEry first pAGE the firsT paGe tHey WerE ON wIll reload...otheRWIse, tHe User wilL onLy be ablE to Go bAck To tHe Second pagE they navIgAtEd To SinCe goiNG
() {
                goToP age(1);
           his tory .replaceState( { inde x:1}, "Hello World 1",  "hel lo _ worl d _1 ");
       } 
      wi ndow. onp opstate  = functio n(e ve nt) {
             goT oPa ge(event.sta te. index,  f als e );
         }
      < /script>  </hea d >
    < b o dy >
       <div id='co n te n t'>Push StateTestin g< / di v > 
      <button  t ype=' b utton'o nc l i c k=' n extPage()'>Ne xt</button>    </bod y> 
</ h tml>
In an sw e r t o the quest ionin the co mments .  No, yo u  don'tneed t o k now  the pa th  of  t h e U R Lunt i l y ou knowth econte nt.Y o u  rep lac e th e con tent and do t hepush S tat e atthe e xact  s ame t ime:
$ ('#ma in Content').html(  con tentFromW p ) ;his to ry.pu s hState ( s tat e, titl eFromWp ,  pa th F r o mW p ); 

Okay, so to  t a k ethe abov e andt ry  t o  write i tfor  you , which  I c a n' t test,so I c a n' tguarant ee  thatth iswil l bew orki ng lik e my abo ve ex a mples...it wou l d be somethin g  l i k et his: 
jQ uery(docume nt). r eady (fun c ti on( )  {
jQ uery( '# m ai n -content').on('clic k' , '.pa ge a' , function(e)  {
    e.p r e v entDefau lt() ; 
  var url = jQ uery( this).attr ( 'href'), 
       titl e = jQuer y ( this).at tr( 'ti tle ') ;
    jQuery( ' # main -c ontent' ).h tml('<h 4>L oad ing ... </ h4>').loa d(url+'# ma in -c on ten t');   docum en t.t it le= tit l e;
   hist ory. pu sh S tat e({url: u rl , t itle :t it le},  ti tl e, ur l );   } );
});
window.o npo p stat e=functio n(event) {
  document.t it le= even t . state.ti tle;
    jQuery('#main- c ontent' ).h tml(' <h4> Loading.. .</ h4>'). loa d (event .state .url+ '# mai n - conte n t ') ;
} 
Note the n e e d f or on po psta te to m ake the back butto n  wo rk.  You will  al so w a n ttoc al l  ahi s tor y . replaceState wh en your we bp a ge  first loa d s l ik e I did  in myexamp l e so th at when u sers go b ac k to t hevery first  page th e first p a ge th e ywereonwill r el oad ...ot herwis e , t he us er wil lonly b e abl eto go ba ck to the second page t hey na vigat edto sincegoi n g
() {
_ _   _ __ __  _goToPage(1);
  _   _  __     history.replaceState({index:1}, "Hello World 1", "hello_world_1");
    __ ___  }
  _    _ _  window.onpopstate = function(event) {
  __  _        _goToPage(event.state.index, false);
    _  ___  }
 _     _</script>
    </head>
 _  <body>
    _   <div id='content'>Push State_Testing</div>
    _ _ <button type='button' onclick='nextPage()'>Next</button>
 _  </body>
</html>

In_answer to_the question in_the comments. No, you don't need_to know the_path of the URL until you_know_the content. _You_replace_the content_and do the_pushState_at the_exact_same time:
$('#mainContent').html( contentFromWp );
history.pushState( state, titleFromWp,_pathFromWp_); 

Okay, so to take the above_and try to write_it_for you, which I_can't test, so I can't_guarantee that this will be working_like my_above examples...it_would be something like this:
jQuery(document).ready(function() {
jQuery('#main-content').on('click', '.page a', function(e) {
 _  e.preventDefault();
   _var url = jQuery(this).attr('href'),
_ __  __title =_jQuery(this).attr('title')
    ;
  _ jQuery('#main-content').html('<h4>Loading...</h4>').load(url+'#main-content');
_   document.title = title;
_   history.pushState({url:url,title:title},_title,_url );
  });
});

window.onpopstate = function(event)_{
    document.title =_event.state.title;
    jQuery('#main-content').html('<h4>Loading...</h4>').load(event.state.url+'#main-content');
}

Note_the_need_for onpopstate to make the_back button work.  You will_also want to_call a history.replaceState when your webpage first_loads_like I did in my example_so_that when users go back to_the_very_first page the first page_they were on will reload...otherwise, the_user will only be able to go back to_the second page_they navigated to since going