Closed nosizejosh closed 4 months ago
I am not sure what's happening, but if the reproduction is exactly like your project, you would need to use Nuxt pages instead of the app.vue
file to be able to use the router.
I found the culprit:
const selected = computed({
get() {
const index = items.findIndex((item) => item.stage === route.query.stage); // Here
if (index === -1) {
return 0;
}
return index;
},
set(value) {
router.replace({ query: { stage: items[value].stage } });
// router.replace({ query: { tab: items[value].label }, hash: '#control-the-selected-index' })
},
});
On the line I highlighted, you are comparing a number
(item.stage
) to undefined | string | string[]
(route.query.stage
).
You should compare it like this:
const selected = computed({
get() {
const index = items.findIndex((item) => item.stage.toString() === route.query.stage?.toString());
if (index === -1) {
return 0;
}
return index;
},
set(value) {
router.replace({ query: { stage: items[value].stage } });
// router.replace({ query: { tab: items[value].label }, hash: '#control-the-selected-index' })
},
});
Whoa! it works Thank you @noook.
how did you catch that?
Experience haha
Also, Typescript does a great job at spotting this, it warns you this condition can never happen because there is no overlap between the types number
and undefined | string | string[]
Description
I have tried to follow as suggested here but I am still unable to get next and previous buttons to work. Please can you check my code to se what I am missing?
I have current version of my code attempts below and also here