Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

203
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda