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.

How to use router-vue.js

See original GitHub issue

Hello,

I’m trying to use the router-vue but I have some problems to dynamically load the right component. Would you have any advice for me, please?

I have something that works without require-vue, I don’t find how to import my vue file into my components routes !

`requirejs.config({ paths: { “Vue”: “./js/libraries/vue”, “vue”: “./js/libraries/require-vuejs”, “VueRouter”: “./js/libraries/vue-router” }, shim: { “Vue”: {“exports”: “Vue”} } });

require([“Vue”, “VueRouter”, ‘vue!./components/test.vue’, ‘vue!./components/HelloWorld.vue’], function(Vue, VueRouter){

const router = new VueRouter({
							routes : [
								{
									path: '/',
									name: 'test',
									component:  { template: '<div>foo</div>', name: 'test'}
								},
								{
									path: '/hello',
									name: 'hello',
									component: { template: '<div>bar</div>', name: 'hello'}
								}
							]
						})

Vue.use(VueRouter);

const app = new Vue({
	router
}).$mount('#app');

});`

Thank you in advance

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
Lospepescommented, Jan 4, 2018

Thanks a lot @edgardleal, it works !

0reactions
edgardlealcommented, Dec 29, 2017

In your code you are registering yours components internally using Vue.component('name', object). I recomend you to export your component as plain object like this:

	define(["Vue"], function(Vue) {
		var component = {
			template: template,
			data: function() {
				return {"msg": "Ok"};
			}
		};
               Vue.component("my-component", component);
                return component;
	});

Now you can use with your current code, and with vue-router too.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting Started - Vue Router
Creating a Single-page Application with Vue + Vue Router feels natural: with Vue.js, we are already composing our application with components.
Read more >
How to Use Vue Router: A Complete Tutorial - Vue School Blog
Let's create a new project and get right into coding. We'll create a new project with vue-cli. If you don't have it installed...
Read more >
How to use vue-router? - CodinGame
Step 1: Make three components inside your components directory. · Step 2: We need to update the index.html file and add the app...
Read more >
Vue JS 3 Tutorial for Beginners #8 - The Vue Router - YouTube
In this Vue 3 tutorial we'll take a look at the Vue Router in order to make a "multi-page" Vue website. We'll see...
Read more >
How to use routing in Vue.js ? - GeeksforGeeks
App.vue ... The <router-view> can be used to display the routing components based on the routes. When applied to an element in a...
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