I am attempting to generate route names based on the routes defined in the Vue Router. My goal is to utilize a helper function called findRouteByName()
to locate a specific route.
However, I encountered an issue when trying to define the parameters of the helper function with the actual route.name
as types. The error message displayed was:
The type 'readonly [{ readonly path: "/"; readonly name: "Root"; readonly children:
readonly []; }, { readonly path: "/somePath"; readonly name: "somePath1"; readonly component:
"Blub"; readonly children: readonly []; }, { readonly path: "/somePath2"; readonly name:
"somePath2"; readonly component: "Blub"; readonly children: ...' is 'readonly' and cannot be assigned
to the mutable type 'RouteRecordRaw[]'.(4104)
Nevertheless, there is a workaround...
For instance: https://i.sstatic.net/2zOGa.png
The example illustrated in the image functions properly if I refrain from assigning the routes the type RouteRecordRaw[]
.
In doing so, I am able to achieve my objective and use the types as parameters in the function successfully.
However, it is imperative that I designate RouteRecordRaw[]
as the type for the routes. Otherwise, an error will occur during router initialization. Therefore, it is necessary to work with RouteRecordRaw[]
.
I have set up everything on Stackblitz, hoping that someone might come up with an elegant solution for this dilemma.