UNPKG

cheetah-framework

Version:

Cheetah Framework JS used in all our applications

47 lines (37 loc) 996 B
import { router } from '@cheetah' import config from '@cheetah/config' const authConfig = config.auth class Router { /** * Deprecated */ static getUrl (routeName, arg) { return route(this.routeNamePrefix + routeName, arg).toString() } /** * Redirect to `redirectPath` query saved by redirectToLogin * or to `/` if empty */ static redirectAfterLogin () { const redirectPath = _.get(router.history, 'current.query.redirectPath') if (redirectPath) { return router.replace(redirectPath) } return router.replace(authConfig.defaultRedirectRoute) } /** * Redirect page after a logout * @return {void} */ static redirectAfterLogout () { router.replace(authConfig.routes.login) } static get routeNamePrefix () { let routeNamePrefix = _.get(config, 'router.namePrefix', '') if (routeNamePrefix) { routeNamePrefix = _.trim(routeNamePrefix, ['.']) + '.' } return routeNamePrefix } } export { Router }