Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a specific route data by route name in VueJs?

In VueJs i can always access the current route data. but what if i want to access a different route's data by its name ? suppose i have routes defined,

[
    {
        name: "dashboard",
        path: "/",
        component: Dashboard,
        meta: {
            title: "Dashboard",
        }
    },
    {
        name: "login",
        path: "/login",
        component: Login,
        meta: {
            title: "Login",
        }
    }
]

now suppose i am in dashboard route. i can access its data by this.$route but what if i want to access the meta data of route named as login ? is there any function which will return me the object of route named login ?

like image 413
Ashraful Islam Tushar Avatar asked Oct 16 '25 02:10

Ashraful Islam Tushar


1 Answers

You can use the resolve method to translate route name into a path like this:

const { href } = this.$router.resolve({
  name: 'password-change',
});

or if you want more information:

const { route } = this.$router.resolve({
  name: 'password-change',
});

in return you get an object containing route path, meta, params etc.

like image 66
Picard Avatar answered Oct 18 '25 16:10

Picard



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!