How to prevent the redirection of a link and even change the url? [duplicate]

0

I have a side menu with several links, I'm using ajax so when someone clicks on one of the links the central content of the page is modified. How would you do this operation ??

I'm currently using this code:

<script>
    $('li:contains(Registro Local)').click(function(event){
    $('.active').removeClass('active');
    $('li:contains(Registro Local)').addClass('active');
    event.preventDefault();
    $('.content_wrap').load('link-da-pagina');

  });

</script> 

This causes the page to load but does not change the url.

    
asked by anonymous 02.02.2017 / 14:08

1 answer

1

You can do pushState (stateObject, title, url)

<script>
    $('li:contains(Registro Local)').click(function(event){
    $('.active').removeClass('active');
    $('li:contains(Registro Local)').addClass('active');
    event.preventDefault();
    $('.content_wrap').load('link-da-pagina');

    history.pushState("", "", '/sua-nova-url');
  });
</script>

The first parameter is an object that is associated with the new page / state / The second is the title of the page, which is ignored The third is the new URL

    
02.02.2017 / 14:50