Changeset View
Changeset View
Standalone View
Standalone View
src/resources/js/bootstrap.js
Show First 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | |||||
}) | }) | ||||
Vue.use(Toast) | Vue.use(Toast) | ||||
Vue.use(VueRouter) | Vue.use(VueRouter) | ||||
window.router = new VueRouter({ | window.router = new VueRouter({ | ||||
mode: 'history', | mode: 'history', | ||||
routes: window.routes | routes: window.routes, | ||||
scrollBehavior (to, from, savedPosition) { | |||||
// Scroll the page to top, but not on Back action | |||||
return savedPosition || { x: 0, y: 0 } | |||||
} | |||||
}) | }) | ||||
router.beforeEach((to, from, next) => { | router.beforeEach((to, from, next) => { | ||||
// check if the route requires authentication and user is not logged in | // check if the route requires authentication and user is not logged in | ||||
if (to.matched.some(route => route.meta.requiresAuth) && !store.state.isLoggedIn) { | if (to.matched.some(route => route.meta.requiresAuth) && !store.state.isLoggedIn) { | ||||
// remember the original request, to use after login | // remember the original request, to use after login | ||||
store.state.afterLogin = to; | store.state.afterLogin = to; | ||||
// redirect to login page | // redirect to login page | ||||
next({ name: 'login' }) | next({ name: 'login' }) | ||||
return | return | ||||
} | } | ||||
next() | next() | ||||
}) | }) | ||||
router.afterEach((to, from) => { | router.afterEach((to, from) => { | ||||
// Remove the (old) error page when changing a page | // When changing a page remove old: | ||||
$('#error-page').remove() | // - error page | ||||
// - modal backdrop | |||||
$('#error-page,.modal-backdrop.show').remove() | |||||
}) | }) | ||||
/** | /** | ||||
* We'll load the axios HTTP library which allows us to easily issue requests | * We'll load the axios HTTP library which allows us to easily issue requests | ||||
* to our Laravel back-end. This library automatically handles sending the | * to our Laravel back-end. This library automatically handles sending the | ||||
* CSRF token as a header based on the value of the "XSRF" token cookie. | * CSRF token as a header based on the value of the "XSRF" token cookie. | ||||
*/ | */ | ||||
window.axios = require('axios') | window.axios = require('axios') | ||||
axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest' | axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest' |