In vue, Why is preferably using :to="{ name: 'home'}"
rather than simply using to:="/"
<template>
<h1>Vue 2:</h1>
<router-link to="/">Home</router-link>
<router-link :to="{ name: 'home'}">Home</router-link>
<router-view/>
</template>
CodePudding user response:
According to named routes in router docs, these are the advantages of using name instead of path :
- No hardcoded URLs
- Automatic encoding/decoding of params
- Prevents you from having a typo in the url
- Bypassing path ranking (e.g. to display a )