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

241
Views
How to use Vue Router for scrolling navigation without loading in new components?

This project uses Vue 3 and Laravel 8.

I want to use vue-router for single page navigation without loading in new components and instead just using the router-links to scroll to sections similar to how anchor tags work:

  <router-link :to="{ hash: '#home' }">Home</router-link>

In Vue 2 I was able to do that by simply removing the component attribute from a route but in Vue 3 I am getting these errors in browser console when I do that:

[Vue Router warn]: Component "default" in record with path "/" is not a valid component. Received "undefined".

[Vue Router warn]: uncaught error during route navigation: app.js:40900

Error: Invalid route component
    at extractComponentsGuards (app.js:42803)
    at app.js:43926

[Vue Router warn]: Unexpected error when starting the router: Error: Invalid route component
    at extractComponentsGuards (app.js:42803)
    at app.js:43926

router.js:

import { createWebHistory, createRouter } from "vue-router";

import Home from "../vue/views/home";
import About from "../vue/views/about";


const router = createRouter({
    history: createWebHistory(),
    routes: [
        {path: "/", name: "home", component: Home},
        {path: "/about", name: "about", component: About},
    ],
    scrollBehavior(to, from, savedPosition) {
        if (to.hash) {
            return window.scrollTo({ top: document.querySelector(to.hash).offsetTop, behavior: 'smooth' });
        }
        return window.scrollTo({ top: 0, behavior: 'smooth' });
    }
});
export default router;

When I don't remove the component attribute from a route like so:

    {path: "/", name: "home"}

the home component is loaded in twice and overlaps either below the home component or is displayed at the end of the page.

How can I prevent that and just use the scrolling functionality?

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!