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

206
Views
Issue when trying to use Nested routes in Vuejs?

main.js

import Vue from "vue";
import App from "./App.vue";
import VueRouter from "vue-router";
import HelloWorld from "./components/HelloWorld";
import User from "./components/User";

Vue.use(VueRouter);

const router = new VueRouter({
  routes: [
    {
      path: "/",
      name: "HelloWorld",
      component: HelloWorld,
      children: [{ path: ":id", name: "User", component: User }]
    }
  ]
});

Vue.config.productionTip = false;

new Vue({
  router,
  render: (h) => h(App)
}).$mount("#app");

HelloWorld.vue

<template>
  <div>
    <div v-for="item in items" :key="item.id">
      <b> id: {{ item.id }}</b>
      <router-link :to="`/HelloWorld/${item.id}`">
        {{ item.title }}
      </router-link>
    </div>
    <!-- end v-for -->
    <router-view></router-view>
  </div>
</template> 

<script>
import { router } from "./router";
export default {
  name: "HelloWorld",
  components: {},
  data() {
    return {
      items: [],
    };
  },
  mounted() {
    router().then((r) => {
      this.items = r.data;
    });
  },
};
</script>

codesandbox:- https://codesandbox.io/s/combined-logic-api-forked-oq808t?file=/src/main.js

in main.js routing file, if i change from path:'/' to path:'/HelloWorld' then output is not displaying. Not sure why and where it is linked with api call..

The reason why i changed from path:'/' to path:'/HelloWorld' because path:'/' in my project, it will consider as login page. So tried changing but getting blank screen.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You should change

const router = new VueRouter({
  routes: [
    {
      path: "/HelloWorld/",
      name: "HelloWorld",
      component: HelloWorld,
      children: [{ path: ":id", name: "User", component: User }]
    }
  ]
});

to

const router = new VueRouter({
  mode: 'history',
  routes: [
    {
      path: "/HelloWorld/",
      name: "HelloWorld",
      component: HelloWorld,
      children: [{ path: ":id", name: "User", component: User }]
    }
  ]
});

(So, add mode: history, to the router.)

More on mode: history in Vue Router v3 here

about 4 years ago · Juan Pablo Isaza Report
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!