How to prevent a link redirect and still change the url?

Asked

Viewed 198 times

0

I have a side menu with several links, I am using ajax so that 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 be loaded but does not change the url.

  • Have you ever read anything about html <Section> ? I think this would help you

1 answer

1

Can do the 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 a new page/status/ The second is the page title, which is ignored The third is the new URL

Browser other questions tagged

You are not signed in. Login or sign up in order to post.