Skip to content

vue router guard #25

@mehrdadphp

Description

@mehrdadphp

hi Akryum

I made a new project with Meteor and vue js
Now I want to be a guardian for registration and login and user panel, but this project does not work and it does not work.

Rouetrs : src/routes.js

export default [
    {
        path: '/login',
        name: 'login',
        component: Login,
        meta: {
            forVisitor : true,
        }
    },
    {
        path: '/register',
        name: 'Register',
        component: Register,
        meta: {
            forVisitor : true,
        }
    },
    {
        path: '/user',
        name: 'DashboardPerson',
        component: DashboardPerson,
        meta: {
            forAuth : true,
        }
    },
]

code guard : src/app.js

router.beforeEach((to, from, next) => {
        console.log('Meteor', Meteor.userId())
        if (to.matched.some(record => record.meta.forVisitor)) {
            if (Meteor.userId()) {
                next('/user')
            }
        }

        if (to.matched.some(record => record.meta.forAuth)) {
            if (!Meteor.userId()) {
                next('/login')
            }
        }
    })

Thank you for helping me .

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions