Looking to retrieve the current route name from a template in order to pass it to a router link (specifically passing the current route to the login view so I can redirect users there after authentication).
Everything functions as expected, but when performing a type check, I encounter the following error:
The '+' operator cannot be applied to type 'symbol'. :to="'/signin/' + $route.name". ~~~~~~~~~~~
My code is fairly straightforward:
<RouterLink
v-if="!userState.signedIn"
:to="'/signin/' + $route.name"
>Sign in</RouterLink
>
Is there a way for me to clarify my code somehow so that TypeScript recognizes that $route.name is indeed a string? Or possibly retrieve the route name in a different manner?
Following TJ Crowder's advice in the comments, I am able to convert/cast the property to a string using:
:to="'/signin/' + String($route.name)"
...however, this approach may fail if $router.name
returns as a symbol
. I have yet to come across a scenario where the value would be a symbol
instead of a string
.