2

js and have a problem to use vue-router, my component isn't rendered and console show no errors, follow my code:

router config (/router/index.js):

import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '@/pages/Home/Home.vue'
import NewUser from '@/pages/NewUser/NewUser.vue'

Vue.use(VueRouter)

const routes = [
    { path: '/', component: Home.default },
    { path: '/NewUser', component: NewUser.default }
]

export default new VueRouter({
    routes
})

main.js:

import Vue from 'vue'
import App from './App.vue'
import router from './router'

import 'primevue/resources/themes/nova-light/theme.css'
import 'primevue/resources/primevue.min.css'
import 'primeicons/primeicons.css'
import 'primeflex/primeflex.css'

import Vuelidate from 'vuelidate'
import Card from 'primevue/card'
import InputMask from 'primevue/inputmask'
import Button from 'primevue/button'
import Sidebar from 'primevue/sidebar'
import InputText from 'primevue/inputtext';
import Message from 'primevue/message';

Vue.config.productionTip = false


Vue.use(Vuelidate)
Vue.component('Card', Card)
Vue.component('InputMask', InputMask)
Vue.component('Button', Button)
Vue.component('Sidebar', Sidebar)
Vue.component('InputText', InputText)
Vue.component('Message', Message)

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

app.vue:

<template>
  <Fragment id="app">
      <Header />
          <router-view />
      <Footer />
  </Fragment>
</template>

<script src="./App.js"></script>
<style src="./App.css"></style>

my router-links is in header component, follow the github repository with the projetc:

https://github.com/juniorjrjl/weblib-front

thank you

[edited]

link removede because i solved part of problem and finally get error message

[edited]

I remove a link because not generate error in a link and I finally get error message after remove '.default' in my routes

vue.runtime.esm.js?2b0e:619 [Vue warn]: Error in nextTick: 
"NotFoundError: Failed to execute 'insertBefore' on 'Node': The node 
before which the new node is to be inserted is not a child of this 
node."

vue.runtime.esm.js?2b0e:1888 DOMException: Failed to execute 
'insertBefore' on 'Node': The node before which the new node is to be 
inserted is not a child of this node.
at HTMLBodyElement.n.insertBefore (webpack- 
internal:///./node_modules/vue-fragment/dist/vue- 
fragment.esm.js:5:1609)
at HTMLDivElement.e.insertBefore (webpack- 
internal:///./node_modules/vue-fragment/dist/vue- 
fragment.esm.js:5:1293)
at Object.insertBefore (webpack- 
internal:///./node_modules/vue/dist/vue.runtime.esm.js:5699:14)
at insert (webpack- 
internal:///./node_modules/vue/dist/vue.runtime.esm.js:6029:19)
at createComponent (webpack- 
internal:///./node_modules/vue/dist/vue.runtime.esm.js:5976:9)
at createElm (webpack- 
internal:///./node_modules/vue/dist/vue.runtime.esm.js:5915:9)
at updateChildren (webpack- 
internal:///./node_modules/vue/dist/vue.runtime.esm.js:6206:11)
at patchVnode (webpack- 
internal:///./node_modules/vue/dist/vue.runtime.esm.js:6309:29)
at VueComponent.patch [as __patch__] (webpack- 
internal:///./node_modules/vue/dist/vue.runtime.esm.js:6472:9)
at VueComponent.Vue._update (webpack- 
internal:///./node_modules/vue/dist/vue.runtime.esm.js:3942:19)
4
  • Can you share a working example that has your problem? Commented Apr 24, 2020 at 13:00
  • I shared my study project in a link, You prefer I create a another exempla more simple? Commented Apr 24, 2020 at 13:05
  • To run your project link, I would have to clone and then install all the dependencies and there is still a chance that I might not face the problem you mentioned. Better is to create a working example like codesandbox. stackoverflow.com/help/minimal-reproducible-example Commented Apr 24, 2020 at 13:08
  • 1
    I add a new link with a simple example in a question Commented Apr 24, 2020 at 13:47

2 Answers 2

1

If you need to have a fallback route when the path does not match any component then do this.

const Foo = { template: "<div>foo</div>" };
const Bar = { template: "<div>bar</div>" };
const NotFound = { template: "<div>Page not found</div>" };

Vue.config.productionTip = false;

Vue.use(VueRouter);

const routes = [
  { path: "/NewUser", component: Bar },
  { path: "/", component: Foo },
  { path: "*", component: NotFound }
];

Working implementation attached.

Edit eager-borg-gbj7r

If you want to create nested router-views then read on it here:
https://router.vuejs.org/guide/essentials/named-views.html#nested-named-views

Sign up to request clarification or add additional context in comments.

3 Comments

I solved part of problem, I remov '.default' in my routes (component property), but get another problem, please look at my comment in shmallen post.
@JoseLuizJunior i do not see the error in the codesandbox I provided. can you check that?
Sorry to leave this question wihout some feedback, I solved my problem after I remove a vue-fragment from my project and replace to div my routes starts to work fine
0

Changing your route did the trick for me. For default routing the syntax is different (see more https://router.vuejs.org/guide/essentials/named-views.html#nested-named-views)

const routes = [
    { path: '/', component: Home },
    { path: '/NewUser', component: NewUser }
]

1 Comment

I remove a '.default' like your example and works to render a component, but when I try to navigate to another link I get a error: [Vue warn]: Error in nextTick: "NotFoundError: Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child of this node." if I refresh a page the component is rendere, but when I try navigate again I get a error

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.