Route aliases and named views
I have this page:
How can I navigate to a specific path when using
navigateTo({name: 'PurchaseError'})
For the moment when using this method it only goes to the original path.7 Replies
Hi @JuanMCe. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
When you use
navigateTo({ name: 'PurchaseError' })
, Nuxt (via vue-router) will always resolve the navigation to the route's canonical path, which is the one defined by the path
property in your definePageMeta
(in your case, /purchase-error/:token?
). The alias
property only allows the same page to be accessible via additional URLs, but programmatic navigation by route name will always use the main path, not an alias.
There is no built-in way in Nuxt or vue-router to programmatically navigate to an alias path using the route name. If you want to navigate to the alias path, you must specify the path directly in your navigateTo
call, like so:
or, if you need to include a dynamic token
:
Aliases are primarily for allowing users to access the same page via different URLs, not for programmatic navigation by name. This behavior is consistent with vue-router's handling of aliases as well Special Metadata: alias.
I'm sorry, but there's no information in the knowledge sources about a way to make navigateTo({ name: 'PurchaseError' })
resolve to an alias path instead of the canonical path. If you need to navigate to the alias, you must use the path directly.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@281911171919904778> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
Can I use
@kapa.ai
Let me check the knowledge base for you again. One moment! :books:
Sorry @JuanMCe, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist:
Perhaps try again in 15mins?
@kapa.ai Can I use
Let me check the knowledge base for you again. One moment! :books:
----------------------
You can use
- When using
navigateTo
with a path directly, like this:
However, if you use the params
property together with a path
, the params will not be automatically injected into the path. The params
property is only used when you navigate by name
, not by path
. When you specify a path
, you need to manually include any dynamic segments (like token
) in the path string itself Docs: navigateTo parameters.
So, this will not work as you might expect:
Instead, you should do:
or, if you want to use an object:
In summary:- When using
path
, include all dynamic segments yourself.
- The params
property is only used when navigating by name
Docs: navigateTo parameters.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@281911171919904778> Kapa.ai is still learning and improving, please let me know how I did by reacting below.