D
D
Dmitry Kazarmin2020-02-06 13:16:47
Vue.js
Dmitry Kazarmin, 2020-02-06 13:16:47

How to organize routing so that 403 and 404 pages work?

I want to organize the display of the error "Page not found" and "Access denied". Below is a route (located last in the list) that catches all paths not previously specified and returns the component with an error

let routes = [
{
        path: '*',
        name: 'page_not_found',
        components: {
            default: NotFoundComponent,
        },
        meta: {
            title: 'page_not_found',
        },
        layout: 'empty'
    },
];


That is, the /blabla path will show "Page not found"

Question. How can I make it show "Access Denied" for some existing path under certain conditions? No redirect. With a redirect, the option is simple and already implemented

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
grinat, 2020-02-06
@fenix163

For example, store an error in the store, if there is, then write it there. Put the error component on the topmost level and then:

<t-error 
            v-if="error"
            :error="error"
          ></t-error>
          <router-view
            v-else
          ></router-view>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question