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

207
Visualizações
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 Respostas
Responde à pergunta

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 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