How to check param route in router

24 Views Asked by At

How can I check a param of a route from a variable like so:

const SUB_ROUTES = {
    GLOBALSTAR: "globalStar",
    PARKINGMULTIPEAJE: "parkingMultipeaje",
    RESERVAS: "reservas",
};

then in the router.ts file check someDomain.com/route/subRoute where subRoute exists inside SUB_ROUTES otherwise being redirected to notFound

1

There are 1 best solutions below

0
tsiPlus On

I manage to solve it using per route guards from the vue docs and redirecting to NotFound.vue component like this:

            {
                path: "/mapas/:maptype",
                name: "MapsClientes",
                component: Mapas,
                props: true,
                beforeEnter: (to, from) => {
                    if (!Object.values(MAP_TYPE).includes(to.params.maptype as string)) router.push({ name: "NoEncontrado" });
                }
            }