Last active
February 7, 2024 00:19
-
-
Save dansp89/7024e18a51c7219631638b69d5ad5d53 to your computer and use it in GitHub Desktop.
Rotas v3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
createRouter, | |
createWebHistory, | |
type RouteRecordRaw, | |
} from "vue-router"; | |
import { useAuthStore } from "@/stores/auth"; | |
import { useConfigStore } from "@/stores/config"; | |
import { filterRoutesByRole } from "@/core/plugins/ManagerAccessDashboard"; | |
export let routes: Array<RouteRecordRaw> = [ | |
{ | |
path: "/", | |
redirect: "/dashboard", | |
component: () => import("@/layouts/default-layout/DefaultLayout.vue"), | |
meta: { | |
middleware: "auth", | |
}, | |
children: [ | |
{ | |
path: "/dashboard", | |
name: "dashboard", | |
component: () => import("@/views/Dashboard.vue"), | |
meta: { | |
pageTitle: "Dashboard", | |
breadcrumbs: ["Dashboards"], | |
}, | |
}, | |
{ | |
path: "/builder", | |
name: "builder", | |
component: () => import("@/views/LayoutBuilder.vue"), | |
meta: { | |
pageTitle: "Layout Builder", | |
breadcrumbs: ["Layout"], | |
}, | |
}, | |
{ | |
path: "/crafted/account", | |
name: "account", | |
component: () => import("@/views/crafted/account/Account.vue"), | |
meta: { | |
roles: ["administrator", "developer", "autenticated", "public"], | |
breadcrumbs: ["Crafted", "Account"], | |
sectionTitle: "account", | |
keenthemesIcon: "", | |
bootstrapIcon: "", | |
}, | |
children: [ | |
{ | |
path: "/crafted/account/overview", | |
name: "account-overview", | |
component: () => import("@/views/crafted/account/Overview.vue"), | |
meta: { | |
roles: ["administrator", "developer", "autenticated", "public"], | |
pageTitle: "Overview", | |
}, | |
}, | |
{ | |
path: "/crafted/account/settings", | |
name: "account-settings", | |
component: () => import("@/views/crafted/account/Settings.vue"), | |
meta: { | |
roles: ["administrator", "developer", "autenticated", "public"], | |
pageTitle: "Settings", | |
}, | |
}, | |
{ | |
path: "/crafted/account/master", | |
name: "account-master", | |
component: () => import("@/views/crafted/account/Settings.vue"), | |
meta: { | |
roles: ["administrator", "developer", "autenticated", "public"], | |
pageTitle: "Master", | |
}, | |
}, | |
], | |
}, | |
], | |
}, | |
{ | |
path: "/", | |
component: () => import("@/layouts/AuthLayout.vue"), | |
children: [ | |
{ | |
path: "/", | |
name: "sign-in", | |
component: () => | |
import("@/views/crafted/authentication/basic-flow/SignIn.vue"), | |
meta: { | |
pageTitle: "Entrar", | |
}, | |
}, | |
// BEGIN:: ROTAS PARA CADASTRO DE CONSULTOR | |
{ | |
// PASSO 1.1 - CONSULTOR (SEM referência de usuário) | |
path: "/seja-consultor", | |
name: "seja-consultor-preload", | |
component: () => | |
import("@/views/crafted/authentication/basic-flow/Preload.vue"), | |
meta: { | |
pageTitle: "Seja consultor", | |
role: "consultor", | |
preload: true, | |
}, | |
}, | |
{ | |
// PASSO 1.2 - CONSULTOR (COM referência de usuário) | |
path: "/seja-consultor/:username", | |
name: "seja-consultor-preload-username", | |
component: () => | |
import("@/views/crafted/authentication/basic-flow/Preload.vue"), | |
meta: { | |
pageTitle: "Seja consultor", | |
role: "consultor", | |
preload: true, | |
}, | |
}, | |
{ | |
// PASSO 2 - CONSULTOR ( Onboarding ) | |
path: "/seja-consultor/onboarding", | |
name: "consultor-onboarding", | |
component: () => | |
import("@/views/crafted/authentication/basic-flow/Onboarding.vue"), | |
meta: { | |
pageTitle: "Seja consultor", | |
role: "consultor", | |
preload: false, | |
}, | |
}, | |
{ | |
// PASSO 5 - CONSULTOR ( Cadastrar ) | |
path: "/seja-consultor/step-4", | |
name: "seja-consultor", | |
component: () => | |
import("@/views/crafted/authentication/basic-flow/SignUp.vue"), | |
meta: { | |
pageTitle: "Cadastrar | consultor", | |
role: "consultor", | |
}, | |
}, | |
{ | |
// PASSO 6 - CONSULTOR ( Simular valores ) | |
path: "/seja-consultor/step-5", | |
name: "seja-consultor-valores", | |
component: () => | |
import( | |
"@/views/crafted/authentication/basic-flow/SignUp-project1-simular.vue" | |
), | |
meta: { | |
pageTitle: "Simular", | |
role: "consultor", | |
}, | |
}, | |
// END:: ROTAS PARA CADASTRO DE CONSULTOR | |
// BEGIN:: ROTAS PARA CADASTRO DE CLIENTE | |
{ | |
// PASSO 1.1 - CLIENTE (SEM referência de usuário) | |
path: "/seja-cliente", | |
name: "seja-cliente-preload", | |
component: () => | |
import("@/views/crafted/authentication/basic-flow/Preload.vue"), | |
meta: { | |
pageTitle: "Seja cliente", | |
role: "cliente", | |
preload: true, | |
}, | |
}, | |
{ | |
// PASSO 1.2 - CLIENTE (COM referência de usuário) | |
path: "/seja-cliente/:username", | |
name: "seja-cliente-preload-username", | |
component: () => | |
import("@/views/crafted/authentication/basic-flow/Preload.vue"), | |
meta: { | |
pageTitle: "Seja cliente", | |
role: "cliente", | |
preload: true, | |
}, | |
}, | |
{ | |
// PASSO 2 - CLIENTE ( Onboarding ) | |
path: "/seja-cliente/onboarding", | |
name: "cliente-onboarding", | |
component: () => | |
import("@/views/crafted/authentication/basic-flow/Onboarding.vue"), | |
meta: { | |
pageTitle: "Seja cliente", | |
role: "cliente", | |
preload: false, | |
}, | |
}, | |
{ | |
// PASSO 5 - CLIENTE ( CADASTRAR ) | |
path: "/seja-cliente/step-4", | |
name: "seja-cliente", | |
component: () => | |
import("@/views/crafted/authentication/basic-flow/SignUp.vue"), | |
meta: { | |
pageTitle: "Cadastrar | cliente", | |
role: "cliente", | |
}, | |
}, | |
{ | |
// PASSO 6.1 - CLIENTE ( Simular valores ) | |
path: "/seja-cliente/:uf/step-5", | |
name: "seja-cliente-valores", | |
component: () => | |
import( | |
"@/views/crafted/authentication/basic-flow/SignUp-project1-simular.vue" | |
), | |
meta: { | |
pageTitle: "Simular", | |
role: "cliente", | |
}, | |
}, | |
{ | |
// PASSO 6.2 - CLIENTE ( Simular valores ) | |
path: "/seja-cliente/step-5", | |
name: "seja-cliente-valores", | |
component: () => | |
import( | |
"@/views/crafted/authentication/basic-flow/SignUp-project1-simular.vue" | |
), | |
meta: { | |
pageTitle: "Simular", | |
role: "cliente", | |
}, | |
}, | |
{ | |
// PASSO 7 - CLIENTE ( Subir arquivos ) | |
path: "/seja-cliente/step-6", | |
name: "seja-cliente-enviar-arquivos", | |
component: () => | |
import( | |
"@/views/crafted/authentication/basic-flow/SignUp-project2-upload.vue" | |
), | |
meta: { | |
pageTitle: "Enviar arquivos", | |
role: "cliente", | |
}, | |
}, | |
{ | |
// PASSO 8 - CLIENTE ( Tela de informar que está em análise ) | |
path: "/seja-cliente/step-7", | |
name: "seja-cliente-analise", | |
component: () => | |
import( | |
"@/views/crafted/authentication/basic-flow/SignUp-project3-analise.vue" | |
), | |
meta: { | |
pageTitle: "Em análise", | |
role: "cliente", | |
}, | |
}, | |
// END:: ROTAS PARA CADASTRO DE CLIENTE | |
// BEGIN:: ROTAS PARA RECUPERAR SENHA | |
{ | |
path: "/recuperar-senha", | |
name: "password-reset", | |
component: () => | |
import("@/views/crafted/authentication/basic-flow/PasswordReset.vue"), | |
meta: { | |
pageTitle: "Recuperar senha", | |
}, | |
}, | |
{ | |
path: "/alterar-senha", | |
name: "password-change", | |
component: () => | |
import( | |
"@/views/crafted/authentication/basic-flow/PasswordChange.vue" | |
), | |
meta: { | |
pageTitle: "Alterar senha", | |
}, | |
}, | |
{ | |
path: "/alterar-senha/:code", | |
name: "password-change-code", | |
component: () => | |
import( | |
"@/views/crafted/authentication/basic-flow/PasswordChange.vue" | |
), | |
meta: { | |
pageTitle: "Alterar senha", | |
}, | |
}, | |
// END:: ROTAS PARA RECUPERAR SENHA | |
], | |
}, | |
{ | |
path: "/", | |
component: () => import("@/layouts/SystemLayout.vue"), | |
children: [ | |
{ | |
// the 404 route, when none of the above matches | |
path: "/404", | |
name: "404", | |
component: () => import("@/views/crafted/authentication/Error404.vue"), | |
meta: { | |
pageTitle: "Error 404", | |
}, | |
}, | |
{ | |
path: "/500", | |
name: "500", | |
component: () => import("@/views/crafted/authentication/Error500.vue"), | |
meta: { | |
pageTitle: "Error 500", | |
}, | |
}, | |
], | |
}, | |
{ | |
path: "/:pathMatch(.*)*", | |
redirect: "/404", | |
}, | |
]; | |
// Filtra as rotas | |
routes = filterRoutesByRole(routes); // ERRO AQUI | |
console.log("filteredRoutes", routes); | |
const router = createRouter({ | |
history: createWebHistory(import.meta.env.BASE_URL), | |
routes, | |
scrollBehavior(to) { | |
// If the route has a hash, scroll to the section with the specified ID; otherwise, scroll toc the top of the page. | |
if (to.hash) { | |
return { | |
el: to.hash, | |
top: 80, | |
behavior: "smooth", | |
}; | |
} else { | |
return { | |
top: 0, | |
left: 0, | |
behavior: "smooth", | |
}; | |
} | |
}, | |
}); | |
router.beforeEach((to, from, next) => { | |
const authStore = useAuthStore(); | |
const configStore = useConfigStore(); | |
const appName = import.meta.env.VITE_APP_NAME; | |
document.title = [to.meta.pageTitle, `${[appName]}`].join(" "); | |
configStore.resetLayoutConfig(); | |
authStore.verifyAuth(); | |
if (to.meta.middleware == "auth") { | |
if (authStore.isAuthenticated) { | |
next(); | |
} else { | |
next({ name: "sign-in" }); | |
} | |
} else { | |
next(); | |
} | |
}); | |
export default router; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment