question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using vue-router with vue-custom-element

See original GitHub issue

I’m very new to Vue and am trying to create a Vue app that can be embedded inside a non Vue app. I am having trouble getting routing to work inside of my Vue app.

I have two components in my app - Schools and School.

in main.js I have this:

import Vue from 'vue'
import VueRouter from 'vue-router'
import App from './App.vue'
import vueCustomElement from 'vue-custom-element'
import Schools from "./components/Schools";
import School from "./components/Schools";

Vue.use(vueCustomElement);
const router = new VueRouter({
    routes: [
      { path: '/', component: Schools },
      { path: '/school', component: School },
    ]
  })
App.router = router;
Vue.customElement('schools-widget', App)

and then in my schools component (Schools.vue) I have

<router-link to="/school">School</router-link>

which I was hoping would link me from my Schools component to my School component.

But I get the error

Unknown custom element: <router-link> - did you register the component correctly?

Are you able to tell me what I am doing wrong?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
richardshergoldcommented, Mar 14, 2021

Thank you for your help - someone helped me with an example and my code works now!

https://stackoverflow.com/questions/66624187/using-router-link-with-vue-custom-element

0reactions
karol-fcommented, Mar 14, 2021

Great!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using <router-link> with vue-custom-element - Stack Overflow
I have two components in my app - Schools and School. in main.js I have this: import Vue from 'vue' import VueRouter from...
Read more >
Using the router *inside* of an Custom Element #19 - GitHub
Is there a way to use the router inside of an Custom Element? ... import Vue from 'vue' import VueRouter from 'vue-router' import...
Read more >
Vue and Web Components
A Vue custom element will mount an internal Vue component instance inside its shadow root when the element's connectedCallback is called for the...
Read more >
Using Custom Elements in Vue.js - bitspeicher.blog
Custom Elements are part of the Web Component specification and allow the use of custom HTML tags. After defining them, they are used...
Read more >
vue-custom-element - npm
Vue -custom-element is a tiny wrapper around Vue components. It provides a seamless way to use Vue components in HTML, plain JavaScript, Vue, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found