Difference between revisions of "Main.js File"

From rbachwiki
Jump to navigation Jump to search
(Created page with "<nowiki>import Vue from 'vue' import App from './App.vue' import VueRouter from 'vue-router'; import { myRoutes } from './routes.js'; Vue.use(VueRouter); const router = new...")
 
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
<nowiki>import Vue from 'vue'
<pre>import Vue from 'vue'
import App from './App.vue'
import App from './App.vue'
import VueRouter from 'vue-router';
import VueRouter from 'vue-router';
Line 30: Line 30:
     router,
     router,
     render: h => h(App)
     render: h => h(App)
})</nowiki>
})</pre>
[[VueJs Routing]]

Latest revision as of 18:05, 17 October 2018

import Vue from 'vue'
import App from './App.vue'
import VueRouter from 'vue-router';
import { myRoutes } from './routes.js';


Vue.use(VueRouter);

const router = new VueRouter({
    routes: myRoutes,
    mode: 'history',
    scrollBehavior(to, from, savedPosition){
        if(savedPosition){
            return savedPosition;
        }
        if(to.hash){
            return{selector: to.hash};
        }
        //return{x:0 , y:700};
    }
});
// get executed on each routing action
router.beforeEach((to, from, next) =>{
console.log('Global before each');
next();
});

new Vue({
    el: '#app',
    router,
    render: h => h(App)
})

VueJs Routing