Skip to content

Instantly share code, notes, and snippets.

@renalpha
Created July 16, 2019 18:34
Show Gist options
  • Save renalpha/863331ca8f90b49980b07906fe4a38ba to your computer and use it in GitHub Desktop.
Save renalpha/863331ca8f90b49980b07906fe4a38ba to your computer and use it in GitHub Desktop.
Vuejs with routing
/**
* First we will load all of this project's JavaScript dependencies which
* includes Vue and other libraries. It is a great starting point when
* building robust, powerful web applications using Vue and Laravel.
*/
require('../js/loadScripts.js');
import Vue from 'vue';
import VueRouter from 'vue-router';
Vue.use(VueRouter);
window.EventBus = new Vue();
const _ = require('lodash');
/**
* Next, we will create a fresh Vue application instance and attach it to
* the page. Then, you may begin adding components to this application
* or customize the JavaScript scaffolding to fit your unique needs.
*/
Vue.prototype.trans = string => _.get(window.i18n, string);
const router = new VueRouter({routes: require('./components/routes/web')});
const files = require.context('./', true, /\.vue$/i);
files.keys().map(key => Vue.component(key.split('/').pop().split('.')[0], files(key).default));
const app = new Vue({
mode: 'history',
router
}).$mount('#app');
module.exports = [
{
path: '/',
component: require('../routes/ExampleComponent').default,
name: 'home'
},
{
path: '/user',
component: require('../routes/User').default,
name: 'user'
}
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment