Routes
Let's understand how the composition of routes for VueRouter in Skeleton is done, since it is done differently from the standard that is usually seen in Quasar or Vue projects
Last updated
Was this helpful?
Let's understand how the composition of routes for VueRouter in Skeleton is done, since it is done differently from the standard that is usually seen in Quasar or Vue projects
Last updated
Was this helpful?
Insrc/router/index.js
is the creation of the application router. There are some details slightly different from the standard that the Quasar template delivers. We will see one about these differences below.
From the beginning ofindex.js
you can see that there is an import for a file calledAppRouter
. This will be seen in a section similar to the section below.
This file is a class that extendsVueRouter
allowing to modify, improve and add behaviors to the router.
In addition to configuring two basemiddleware
, there is also the configuration of the routes. This configuration is done in a different way, instead of "pulling" the routes and adding them as an argument in the construction of therouter
functions are imported (also calledRouteFile
) that receive the $ router as an argument so that each module is responsible for add your routes.
This change allows the modules to have more independence over the configurations they can make in the project. So, instead of having just onebeforeEach
, for example, we will have severalmiddleware
of this type distributed by the project.
RouteFile
TheRouteFile
of the Authmodule
is located insrc/modules/Auth/router/routeFile.js
and is very simple, with only one route. As mentioned earlier, it receives the router as a parameter and uses theaddRoutes
method to add the routes. In this case, helpersroute
and group
are being used to create the routes. These functions build objects compatible with RouteConfig which are the traditional route structures.
RouteFile
Allocated insrc/modules/Dashboard/router/routeFile.js
theDashboard
route composition will be much more extensive than that ofAuth
. Thismodule
will house the entire "control panel", so instead of defining all routes in it, imports of other route files are made. The other routes are close to the Schema domain and must always export arrays. In order to access the resources that will be created, it will be necessary to register the routes that we create in this file, so it will be remembered later.
A route file simply needs to export a function that returns an array of routes like the image below.
When creating a large number of screens, it is common to repeat several sections and configurations several times. To speed up the creation it is possible to use some helpers to create routes for CRUD, as can be seen in the example below.
This section above creates a set of 5 properly configured routes. To use some resources that are preconfigured in the project, it is necessary to configure some details in the route meta. Thecrud
function already solves this and introduces thescope
andnamespace
in the route meta
, allowing additional configurations to be passed. The following example is an excerpt from the src/app/Util/routing.js
.