I have a project using vue 3 and vue router 4, my issue is that it redirects me to 404 page after I reload the page. It works when I'm navigating using route links.
The route that I'm trying to access is added to route list after user login.
Below are my codes.
Create routes
export const adminRoutes = [...Dashboard, ...Delivery, ...Couriers];
const routes: Array<RouteRecordRaw> = [...staticRoutes, ...Dashboard];
const router = createRouter({
history: createWebHistory(), //createWebHistory(process.env.BASE_URL),
routes
});
404 Route
{
path: "/:pathMatch(.*)*",
// redirect: "/404",
component: () =>
import(/* webpackChunkName: "Error404" */ "../views/Error404.vue")
}
Add admin routes after login
const dynamicRoutes = generateRoutes(userPermission);
AuthStore.dispatch(AuthActions.SET_ROUTES, dynamicRoutes);
dynamicRoutes.forEach((route: RouteRecordRaw) => {
router.addRoute(route);
});
console.log("NEXT ROUTE -------------", to);
console.log("ROUTER LIST -------------", router.getRoutes());
next();
After user login then reload /delivery, /delivery/edit it redirects to 404 page, but /delivery, /delivery/edit is in the route list based on the console output.