A
A
askold20132018-02-02 18:48:52
Vue.js
askold2013, 2018-02-02 18:48:52

How to restrict access to vue routes from server (middleware)?

Hello!
Such a question - how to restrict user access to some routes, like how it is done in express? For example, we have a page that can be accessed only if the server allows us (that is, when we try to navigate, we send a request, if the server answers "yes" - then we go.
My routes are described as follows:

const routes = [
    { path: '/', component: require('../components/mainPage') },
    { path: '/edms', component: require('../components/mainPage') },
    { path: '/edms/addNew', component: require('../components/addNewDocPage') },
    { path: '/edms/404', component: require('../components/404') },
    { path: '/edms/admin', component: require('../components/admin') },
    { path: '/edms/superAdmin', component: require('../components/superAdmin') },
    { path: '/edms/:id', component: require('../components/detailsPage') },
    { path: '*', component: require('../components/404') },
];
export default routes;

And we need to make two different checks - when trying to go to /edms/admin' - we make 1 request to the server, when going to /edms/superAdmin - another.
Can it be done?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem0071, 2018-02-02
@Artem0071

here
you do beforeeach
if route == admin, then you make a request to the server for permission

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question