Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
82
rated 0 times [  84] [ 2]  / answers: 1 / hits: 25742  / 3 Years ago, thu, january 14, 2021, 12:00:00

I'm creating a Vue3 application and after I added the router, my first page is loading but it's completely blank.


I'm receiving the following



Errors: Uncaught TypeError: Object(...) is not a function



In console:



Warning in ./src/router/index.js "export 'createRouter' was not found
in 'vue-router'


Warning in ./src/router/index.js "export 'createWebHistory' was not
found in 'vue-router'



router -> index.js


import { createWebHistory, createRouter } from "vue-router";
...

const routes = [{
path: "/user/create",
name: "createUser",
component: createUser,
},
{
path: "/users",
name: "listUser",
component: listUser,
meta: { requiresAuth: true }
},
{
path: "/user/show/:id",
name: "showUser",
component: showUser,
meta: { requiresAuth: true }
},
{
path: "/user/update/:id",
name: "updateUser",
component: updateUser,
},
{
path: "/login",
name: "login",
component: Login
},
{
path: "/register",
name: "register",
component: Register
},
{
path: "/users/bearer",
name: "bearer",
component: bearer,
meta: { requiresAuth: true }
}

]

const router = createRouter({
history: createWebHistory(),
routes,
});

router.beforeEach((to, from, next) => {
const requiresAuth = to.matched.some(record => record.meta.requiresAuth);
const isAuthenticated = firebase.auth().currentUser;
console.log("isauthenticated", isAuthenticated);
if (requiresAuth && !isAuthenticated) {
next("/login");
} else {
next();
}
});

export default router;

More From » html

 Answers
28

Found the answer to this here:


Stackoverflow question


You need to install the router via npm


npm install vue-router@next --save

[#50451] Tuesday, December 22, 2020, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
xavier

Total Points: 711
Total Questions: 91
Total Answers: 121

Location: Gabon
Member since Sat, Jul 25, 2020
4 Years ago
;