-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrouter.js
75 lines (70 loc) · 1.84 KB
/
router.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { createRouter, createWebHistory } from 'vue-router';
import TeamsList from './pages/TeamsList.vue';
import UsersList from './pages/UsersList.vue';
import TeamMembers from './components/teams/TeamMembers.vue';
import NotFound from './pages/NotFound.vue';
import TeamsFooter from './pages/TeamsFooter.vue';
import UsersFooter from './pages/UsersFooter.vue';
const router = createRouter({
history: createWebHistory(),
routes: [
{ path: '/', redirect: '/teams' },
{
name: 'teams',
path: '/teams',
meta: { needsAuth: true },
components: { default: TeamsList, footer: TeamsFooter },
children: [
{
name: 'team-members',
path: ':teamId',
component: TeamMembers,
props: true
} // /teams/t1
]
}, // our-domain.com/teams => TeamsList
{
path: '/users',
components: {
default: UsersList,
footer: UsersFooter
},
beforeEnter(to, from, next) {
console.log('users beforeEnter');
console.log(to, from);
next();
}
},
{ path: '/:notFound(.*)', component: NotFound }
],
linkActiveClass: 'active',
scrollBehavior(_, _2, savedPosition) {
// console.log(to, from, savedPosition);
if (savedPosition) {
return savedPosition;
}
return { left: 0, top: 0 };
}
});
router.beforeEach(function(to, from, next) {
console.log('Global beforeEach');
console.log(to, from);
if (to.meta.needsAuth) {
console.log('Needs auth!');
next();
} else {
next();
}
// if (to.name === 'team-members') {
// next();
// } else {
// next({ name: 'team-members', params: { teamId: 't2' } });
// }
// next();
});
router.afterEach(function(to, from) {
// sending analytics data
console.log('Global afterEach');
console.log(to, from);
});
export default router;