Skip to content

Route Permissions

TIP

This document was generated by machine translation. If there are any errors, please inform us

Guide

Fixed Routes (Routes Accessible Without Permission)

In static route mode, route permissions are controlled by meta.constant. Routes with constant set to true can be accessed without logging in; In dynamic route mode, routes accessible without logging in need to be returned in the fetchGetConstantRoutes interface. In other words, routes with constant set to true returned in fetchGetUserRoutes will not take effect and still require login to access;

Permission Routes

In static route mode, by default, routes require login to access. To configure permissions, you can add the meta.roles field. This field's type is string[], configured in UserInfo. If a matching role is found, access is allowed, otherwise not. Matching occurs in the pre-route guard phase; In dynamic route mode, meta.roles can still be used, but it's generally preferred to let the backend control the route table return based on role permissions, excluding unauthorized routes;

Dynamic Routes

Modify the source of routes. The route table for static routes comes from ./src/router/elegant/routes.ts, while the route table for dynamic routes comes from the fetchGetConstantRoutes and fetchGetUserRoutes interfaces.

Note

The type of the route table returned by the interface must be consistent with the frontend's static route table type. Before attempting modifications, it is advisable to familiarize yourself with the project's unique route plugin and route table structure

Enable/Disable

Enable/disable dynamic route mode by configuring the VITE_AUTH_ROUTE_MODE variable in the .env file.

Code Location

.env

dotenv
# auth route mode: static | dynamic
VITE_AUTH_ROUTE_MODE=dynamic

Publish under the MIT license