MCPcopy Create free account
hub / github.com/linuxfoundation/crowd.dev / createRouter

Function createRouter

frontend/src/router/index.js:39–88  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

37 * @returns {Router|{x: number, y: number}}
38 */
39export const createRouter = () => {
40 if (!router) {
41 router = createVueRouter({
42 history: createWebHistory(),
43 routes,
44 scrollBehavior() {
45 return { x: 0, y: 0 };
46 },
47 });
48
49 const originalPush = router.push;
50 router.push = function push(location) {
51 return originalPush
52 .call(this, location)
53 .catch((error) => {
54 console.error(error);
55 ProgressBar.done();
56 });
57 };
58
59 router.beforeEach(async (to, from, next) => {
60 if (to.name && to.name !== from.name) {
61 ProgressBar.start();
62 }
63 const matchedRoute = to.matched.find(
64 (m) => m.meta.middleware,
65 );
66 if (matchedRoute !== undefined) {
67 const context = {
68 from,
69 router,
70 to,
71 store,
72 next,
73 };
74
75 await authGuard(context);
76 await unauthGuard(context);
77
78 next();
79 }
80 });
81
82 router.afterEach(() => {
83 ProgressBar.done();
84 });
85 }
86
87 return router;
88};
89
90export {
91 router,

Callers 1

main.tsFile · 0.90

Calls 4

doneMethod · 0.80
startMethod · 0.65
errorMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected