@hperchec/scorpion-ui-template-default
Version:
Scorpion UI - Default template
93 lines (89 loc) • 2.27 kB
JavaScript
/**
* @vuepress
* ---
* title: Login route
* headline: Login route
* sidebarTitle: .Login
* sidebarDepth: 0 # To disable auto sidebar links
* prev: false # Disable prev link
* next: false # Disable prev link
* ---
*/
import { Core, utils } from '@hperchec/scorpion-ui'
const { capitalize } = utils
const translate = (...args) => Core.context.services['router'].options.translate(...args) // eslint-disable-line dot-notation
/**
* @name Login
* @static
* @type {PublicRoute}
* @description
* - **Name**: Login
* - **Path**: `/login`
* - **Params**: *none*
* - **Query**: *none*
*/
export default {
/**
* @description Route path
* @name Login.path
* @type {string}
* @default /login
*/
path: '/login',
/**
* @description Route name
* @name Login.name
* @type {string}
* @default Login
*/
name: 'Login',
/**
* @description Route component
* @alias Login.component
* @type {Object}
* @default Login
*/
component: () => Core.context.vue.components.public.views.login.Index,
/**
* Options
*/
options: {
/**
* @description Route meta
* @alias Login.meta
* @type {Object}
*/
meta: {
/**
* @alias Login.meta.pageMeta
* @type {Object}
* @property {Function} title - Return translated Login view title (translate: `views.Login.Index.title`)
* @description
* Return translated Login view title (translate: `views.Login.Index.title`)
*/
pageMeta: {
title: (vm) => capitalize(translate('views.Login.Index.title'))
}
},
/**
* @alias Login.beforeEnter
* @type {Function}
* @return {void}
* @description
* > See also [beforeEnter per-route guard documentation](https://v3.router.vuejs.org/guide/advanced/navigation-guards.html#per-route-guard)
*
* Redirect if already authenticated
*/
beforeEnter: async (to, from, next) => {
const authenticated = Core.store.state.Core.Auth.currentUser
// Redirect if authenticated
if (authenticated) {
next({
path: from.fullPath
})
} else {
next()
}
}
}
}