Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

226
Visualizações
Change page and change URL without refresh and keep content after refresh , like ReactJS website

I've tried to use jQuery's load() function to change/load content without reloading. That works, but the problem is: the URL keeps the same!

Even if i use history.pushState() to change URL, that does not solve the problem. Example:

with the famous window.history.pushState("object or string", "Title", "/new-url");

  1. With that, I am creating a "fake URL" for each page - If I try to enter the website with this changed URL again, i get an error, basically the link does not exist;
  2. If I refresh the page, i lost all Ajax loaded content - I need to keep the content when refresh;
  3. When I click to change Ajax loaded page, keeps putting new links next to the previous one, as in the image sent;
  4. I want to get this result: https://reactjs.org/ - transiting the pages, they do not reload and the link changes, it is updatable and the link works separately - how do i do it?

3) printscreen of my page and its url

Important: index.html, about.html and contact.html are existing files that will load with the jquery function below.

HTML:

<div class="navbar">
    <div class="content">
        <div class="logo">My logo</div>
        <ul class="pages">
            <li id="index">Index</li>
            <li id="about">About us</li>
            <li id="contact">Contact</li>
        </ul>
    </div>
</div>

<section id="page"> 
    <div class="content">
        <!-- PAGES LOAD HERE -->
    </div>
</section>

<div class="footer">
    <div class="content">
        --Footer-- All rights reserved.
    </div>
</div>

JS:

    $(document).ready(function () {
        $('li').on("click", function () {
            $pageName = $(this).attr('id');
            $('#page .content').load(`pages/${$pageName}.html`);
            $('li').removeClass('active'); //only to remove the selection of actual page in CSS
            $(this).addClass('active'); //only to add the selection of actual page in CSS
            window.history.pushState("object or string", "Title", `pages/${$pageName}.html`);
        })

    })
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

you're describing "routing" which is the idea of URLs matching the content that is being display.

In jquery i'd recommend googling: jquery router or javascript router

IF you're writing other languages you can google [language] router.

most recently google is bringing up https://www.npmjs.com/package/jqueryrouter which is now forwarding to https://github.com/scssyworks/silkrouter

Once you choose a router, read the docs and come back with more questions.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda