Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

garethdaine's avatar

Spark & Vue-Router...

Hey Folks,

Has anyone had any success in setting up Spark to utilise vue-router to create a Single Page App (SPA)?

Looking for any advice anyone might have.

I did find this resource http://christoph-rumpel.com/2016/05/Larave-Spark-Using-Vue-Component/ but wondered if others might be approaching it in a different way. Thanks.

Gaz

0 likes
3 replies
garethdaine's avatar

So, I've dug a little deeper, and I've decided to go down a different route.

I've gone with using default Spark functionality, specifically using the tab-state mixin and the sparkHashChanged event.

So, in my home component:

Vue.component('home', {
    props: ['user'],

    /**
     * Load mixins for the component.
     */
    mixins: [require('./../spark/mixins/tab-state')],

    ready() {
        this.usePushStateForTabs('.spark-settings-tabs');
    }
});

Then:

Vue.component('courses', {
    data() {

        return {

            test: ''

        }

    },

    ready() {
        //
    },


    events: {
        /**
         * Handle the Spark tab changed event.
         */
        sparkHashChanged(hash) {
            if (hash == 'courses') {
                this.getTest();
            }

            return true;
        }
    },

    methods: {
        getTest() {
            this.$http.get('/dashboard/test')
                .then(response => {
                    this.test = response.data;
                });
        }
    }
});

In my component, and finally setting up my primary layout and tab content as per Spark settings views.

Seems to work pretty well.

This is only basic at the moment, so I may come across issues as I build out functionality, but so far so good.

I can create individual views tied to specific Spark components, that pull through and render whatever data I want, but only load it once the hash has changed. Pretty decent stuff.

I'll probably look deeper into vue-router at a later date. Any questions, let me know.

egroeg's avatar

Yo! Just wanted to say thanks. This saved me a bit of time.

Please or to participate in this conversation.