Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

249
Views
Vanilla JS SPA routing, index.html with dynamic elements

I am trying to make routing on a SPA project, but for some reason it says that my function is undefined. I am new to this so I might overlooked something, I have searched all over the internet and I found this solution and a hash solution.

What I want on my project is that if I click on ABOUT/CONTACT/HOME buttons to render its page content, or if I click on a card item, the cards page should render, with information about that same card

const gridContainer = document.querySelector('.grid_container');


const routes = {
    '/': homePage,
    '/about': aboutPage,
    '/contact': contactPage,
    '/products:id': productPage
};
gridContainer.innerHTML = routes[window.location.pathname];

function navigate(pathName) {
    window.history.pushState({}, pathName, window.location.origin + pathName);
    gridContainer.innerHTML = routes[pathName];
};
window.onpopstate = () => {
    gridContainer.innerHTML = routes[window.location.pathname];
};





function listAllProducts() {
    http.get(productsURL).then((products) => {
        ui.showProducts(products);
    })
}
<ul class="navbar_list">
            <li class="navbar_list_item"><a href="#" class="navbar_list_item_link">Home</a></li>
            <li class="navbar_list_item"><a href="#" onclick="navigate('/about'); return false" class="navbar_list_item_link">About</a></li>
            <li class="navbar_list_item"><a href="#" class="navbar_list_item_link">Contact</a></li>
          </ul>

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!