Route that has empty string as optinal param value is not active
Reproduction
https://play.vuejs.org/#eNq1VduO2zYQ/ZWptoC9qC163W0etIqz2yDotuglSIO+VH2QJdpmViIJkvI6EPTvHZK6+bLJU2DYFud6ZuYMVQdlynj4SQdRwEoplIEaMkVTQx+khAY2SpQw2Vd0kvDWQInKUNVqQuKPg9r6dbpUytD7JryPOsXvdcIBwkrTqXf351JU3EwnV+g2uQ5mQeuO2GJDS1mg/8oaxrub1SMtCmGTfRcTPDqxdH/4oI0SfLt6WylFeYsYZGp2UUxaHdQ1fO8U4aYqiveohKZxYYiPE/N03wX84FD+zvgTGPE6CUgSrH4R+AyPoqQxGfQveqRrlPRuD/Z05heTLmds53Ic6x9Gn4G0dq06Jn1jsF++lxen+Qcthfr8yLTBv1kr9HHHU5730+znaQt0qbuhdoJ2st3YbUFHdr1koIDgup2Ghtfwry2l9nOBCZkgLIHBOI4sGtI2s2Mz10cSlSKnU4xjrt+gI09LikqnO44z4LKB/juBoRDGuBfT2ibb+TZFl3o3vXZ4fBH42CB1E04Prgk53aRV0cXGiYx7ZWmsM8WkwcGdOLi0JTU7kevInwC24qNw8KfXnQjAILjQE1eFstK7aX1UvMVj7Xzb7C+SGlnfJcbDyS4tVx1K3KSlF64rYwSH+6xg2ROyt4dySmBveMbEo9kPhYOmprLbNbATJ4Wl5JevmhrwinCTmfVPL/D1KyX2gIYac7YHbT4XFOvLmUZ7nPimoIc79zvPmaKZYYIjD0RRlfwOtqmM4FYe7rAN53seuUWvj8kITRLAVTtnp2b6AcPuqdWs6ro/vkEX9zQB9ObCQHtsmq9cMBcTz3BjVFpaOtldQfmk+TZgYoKtPKOAH+G8TCVeSIIjCRyHk1ahk6AnehIMo7TiJNgZI3VESMXl0zZEkpDB4v42/Cm8wZzajKQh1eV8rcSzdjdgEjj+29j3aERyujdCFHqeSvZSijPD+1fhK8xUsDXB6ITxnB5cbLdauFlYptF4nWzY9qRIy2tWUPWXtAw6LjbFN9fzb05mVEV7oNmOZk8X5J/0wUN+ryhWt6ej4kyqthS30qrf/f0nPeBzr8S5VwVaf0H5gWrktsXozX6ueI6wR3YO7a9uZoxvP+p3B0O57oqyQLuLph3k2y+UPsD9MbwdddHtoQ4zbV9d+A6cgX3Beb+1UDlVESzlARAsy+FqsVjcuRsTwzE+Xwu8hMoIbhZ2NVEu0zxHsL0EsyQcw8IKUvgBv/6+9d4F3eB7Ymy5W44zD+EHAFmWjQBEsMDPso0QNP8DxAop6w==
Steps to reproduce the bug
- Open playground
- Click "Go to About" (go to about does navigation by pushing record by name).
- See the view
Expected behavior
The second link should be active as it contains an empty string (no parameter is set)
Actual behavior
The second link is not active
Additional information
I'm not totally sure if it is a bug or correct behavior, but you often need to set the param as an empty string to reset the param value. Because null or undefined couldn't be set as a value to reset the param, they will be kept instead. So if we consider an empty string as an empty parameter, it should be aligned with null and undefined behavior in this case
There are some inconsistencies when it comes to optional params and their value for empty strings and null. They were mostly related to allowing a trailing slash or not and to make the type of the param simpler to use (always strings) given that in js we usually just check for falsy so null and an empty strings end up being checked the same way. However, with the upcoming custom resolvers, it might be a good time to make this behavior consistent and stricter: an optional (non repeatable) param could always be null if not passed and string with at least one character otherwise
it might be a good time to make this behavior consistent and stricter: an optional (non repeatable) param could always be null if not passed and string with at least one character otherwise
I agree. It makes a lot of sense to me