refactor: went to router-view instead of hard loading
This commit is contained in:
parent
7928abf9e8
commit
3862c3c3fe
2 changed files with 38 additions and 18 deletions
17
src/App.vue
17
src/App.vue
|
|
@ -1,18 +1,12 @@
|
||||||
<template>
|
<template>
|
||||||
<Login />
|
<div id="app">
|
||||||
<LoggedinPage />
|
<router-view />
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import Login from './components/UserLogin.vue';
|
|
||||||
import LoggedinPage from './components/LoggedinPage.vue';
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'App',
|
name: 'App'
|
||||||
components: {
|
|
||||||
Login,
|
|
||||||
LoggedinPage
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
@ -23,6 +17,5 @@ export default {
|
||||||
-moz-osx-font-smoothing: grayscale;
|
-moz-osx-font-smoothing: grayscale;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
color: #2c3e50;
|
color: #2c3e50;
|
||||||
margin-top: 60px;
|
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
@ -1,11 +1,24 @@
|
||||||
import { createRouter, createWebHistory } from 'vue-router';
|
import { createRouter, createWebHistory } from 'vue-router';
|
||||||
import Login from '../components/UserLogin.vue';
|
|
||||||
import LoggedinPage from '@/components/LoggedinPage.vue';
|
|
||||||
|
|
||||||
|
// Lazy load components for better performance
|
||||||
const routes = [
|
const routes = [
|
||||||
{ path: '/', component: Login },
|
{
|
||||||
{ path: '/logged-in', component: LoggedinPage}
|
path: '/',
|
||||||
//{ path: '/dashboard', component: () => import('../components/Dashboard.vue') }, // Placeholder for a dashboard page
|
name: 'Home',
|
||||||
|
component: () => import('../components/Home.vue')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/login',
|
||||||
|
name: 'Login',
|
||||||
|
component: () => import('../components/UserLogin.vue')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/logged-in',
|
||||||
|
name: 'LoggedIn',
|
||||||
|
component: () => import('../components/LoggedinPage.vue'),
|
||||||
|
// Optional: Add route guard to check if user is actually logged in
|
||||||
|
meta: { requiresAuth: true }
|
||||||
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
const router = createRouter({
|
const router = createRouter({
|
||||||
|
|
@ -13,4 +26,18 @@ const router = createRouter({
|
||||||
routes,
|
routes,
|
||||||
});
|
});
|
||||||
|
|
||||||
export default router;
|
// Optional: Navigation guard example
|
||||||
|
router.beforeEach((to, from, next) => {
|
||||||
|
// Check if route requires authentication
|
||||||
|
if (to.meta.requiresAuth) {
|
||||||
|
// Check if user is logged in (implement your auth logic)
|
||||||
|
const isLoggedIn = localStorage.getItem('user') || sessionStorage.getItem('user');
|
||||||
|
if (!isLoggedIn) {
|
||||||
|
next('/login');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
|
||||||
|
export default router;
|
||||||
Loading…
Add table
Add a link
Reference in a new issue