Join the Stack Overflow Community
Stack Overflow is a community of 6.6 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I am trying to link between (VueJS 2) components using (vue-router 2) router-link. When a link is clicked, the URL is not updated used in blade (laravel 5.3) i used router-link and already v-link is replaced so can i get any example to use vue-router in blade (laravel 5.3 last version)

console error : router is undefined

app.js

window._ = require('lodash');
    window.$ = window.jQuery = require('jquery');
    require('bootstrap-sass');
    window.Vue = require('vue');
    window.VueRouter = require('vue-router');
    require('vue-resource');
    Vue.use(VueRouter)
    var App = Vue.extend({});
    //var router = new VueRouter();
    var router = new VueRouter({
        routes: [
            //{ path: '/', component: require('./components/Example.vue') },
            { path: '/AddServices', component: require('./components/Test.vue') }
        ]
    });
    new Vue({
            el: '#appp',
            router: router,
            render: h => h('router-view')
    });

    Vue.http.interceptors.push((request, next) => {
        request.headers.set('X-CSRF-TOKEN', Laravel.csrfToken);

        next();
    });
    // import Echo from "laravel-echo"

    // window.Echo = new Echo({
    //     broadcaster: 'pusher',
    //     key: 'your-pusher-key'
    // });

balde have link app.blade.php

<router-link to="/AddServices">/AddServices</router-link>
<router-link to="/AddServices"><a>/AddServices</a></router-link>

blade have id to make action home.blade.php

<div class="container">
    <div class="row" id="appp">
            <router-view></router-view>
        </div>
    </div>
share|improve this question
    
You are supposed to share the code where you declare your app, routes, etc. No one can't tell you where you've mistaken if we can't see the piece of code responsible for your errors. – Developer 2 days ago
    
thanks for reply there my code – amryami 2 days ago

First thing first, you don't need to create new router instance

var router = new VueRouter({
...

and have the

Vue.use(VueRouter) // you can remove that one

Second, how do you expect the url to change if you have only 1 url ?

Try this router

var router = new VueRouter({
    routes: [
        { path: '/', component: require('./components/Example.vue') },
        { path: '/AddServices', component: require('./components/Test.vue') }
    ]
});

And here are links (and don't put <a> tags inside <router-link>

<router-link to="/">/index</router-link>
<router-link to="/AddServices">/AddServices</router-link>
share|improve this answer
    
i use router-link in my blade didnt make any action after click and its show in browser not link and see in console error : router is undefined – amryami 2 days ago
    
The only thing I can come up with is if you haven't installed vue-router ? npm install vue-router ? Other than this I don't see anything wrong with the code. Anyway here is a working example of what you're trying to achieve raw.githubusercontent.com/tsvetant/laravue/master/resources/‌​… from my learning sessions with vue. Maybe you can track a mistake you've made using this. – Developer 2 days ago
    
all my problem when i use router-link in blade didnt make link its show only normal string not link in browser and see consol said route is undefined and i allready instaled "vue": "^2.0.1", "vue-resource": "^1.0.3", "vue-router": "^2.1.1" – amryami yesterday

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.