A
A
Amuri2022-02-07 10:44:44
Vue.js
Amuri, 2022-02-07 10:44:44

How to make a redirect from a non-existent page?

There is a router setting like this:

{
    path: "/users/:id",
    name: "User",
    component: User,
  },
  {
    path: "/users/:id/edit",
    name: "EditUser",
    component: EditUser,
  },

It is necessary that when the user goes directly to the /users/:id or /users/:id/edit link, where the id does not exist in the database,
redirect the user to the main page.
https://github.com/Tshashurin/admin-panel

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ice, 2022-02-07
@Amuri

You can determine whether a page exists or not only after querying the database.
Use the beforeCreate or create hook on the page in which to query the database.
You do a check on the result and either display the page based on the data received or do a redirect through the route.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question