-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How can I use nuxt-typed-router
with @nuxtjs/i18n
?
#48
Comments
Hi! What do you mean? |
Hello, @victorgarciaesgi. I think they were referring to the ability of using // Won't work 🚫
router.push({
name: "article",
query: { id: article.id },
);
// Works ✅ but type checking is lost
const localePath = useLocalePath();
router.push(
localePath({
name: "article",
query: { id: article.id },
})
); <!-- Won't work 🚫 -->
<NuxtLink :to="{ name: 'article', query: { id: article.id } }">
some article
</NuxtLink>
<!-- Works ✅ but type checking is lost -->
<NuxtLink
:to="localePath({ name: 'article', query: { id: article.id } })"
>
some article
</NuxtLink> Is it possible that this library can be compatible with the |
Hi @the94air , thanks for a so detailed response!! |
@victorgarciaesgi Correct. Due to the limited access to nuxt configs from a nuxt module, there won't be a way to detect if the |
Just made a quick deep dive, I can lookup automatically for |
@the94air Okay managed to add support for You can try it on |
That's awesome @victorgarciaesgi. I'll test it and let you know 👍 |
No problem! Thanks for the provided details 🙏 |
Hi @victorgarciaesgi, |
Hi! Hmm maybe it doesn't support this syntax, I will test and publish an update to catch all module declarations syntaxes |
It would be great, thanks! |
@szulcus Done on |
@victorgarciaesgi could you take a look? |
@szulcus yep types were not compatible, was tricky but managed to fixed. Try |
@victorgarciaesgi I still have that problem there 😕. If it helps, I can create a reproduction. |
Oh weird didn't reproduce, yeah if you can it would help 😁 |
Ok comes from the fact you navigate by string path, fixed the bug. |
To fix your type issue you have to navigate by name |
@victorgarciaesgi Thank you, I really appreciate your efforts in adding this feature. I have tested router.push(localePath({ name: "index___en" }));
router.push(localePath({ name: "index___fr" })); So currently with the correct locale name, it returns this type error: router.push(localePath({ name: "index" })); // Type '"index"' is not assignable to type 'RoutesNamesList | undefined'. Although the right |
Thanks again for the explanation @the94air! I will release the fix on a major version along with path navigation check because removing them could break some apps. |
By the way, the |
Great job on v3.0.0 so far but the typings are still broken when navigating by name instead of by path. Currently, using the following : I have the following behaviour: navigateTo(localePath('/account/auth/login')) // Will work
navigateTo(localePath({ name: 'account-auth-login' })) // Will raise a TS error In my I'd be happy to provide any additional information if you want 👍 |
Hi @kerunix! Try |
Should be nearly ready, I need to write more tests and docs for it! |
@victorgarciaesgi Thanks for the quick response but I just tried updrading to |
Hmm that's weird, can you share me your |
Sure, here's the output of
And here is everything relevant for the export const i18n: NuxtI18nOptions = {
locales: [
{
code: 'en',
iso: 'en-US',
file: 'en-US.json',
},
{
code: 'fr',
iso: 'fr-FR',
file: 'fr-FR.json',
},
],
defaultLocale: 'fr',
lazy: true,
langDir: 'locales/',
strategy: 'prefix_and_default',
rootRedirect: 'fr/',
vueI18n: {
fallbackLocale: 'fr',
legacy: false,
fallbackWarn: false,
missingWarn: false,
},
} And here are the typings generated by /**
* Exhaustive list of all the available route names in the app
* */
export type RoutesNamesList =
| 'account-auth-email-verify-id-hash___en'
| 'account-auth-forgot-password___en'
| 'account-auth-login___en'
| 'account-auth-reset-password-email___en'
| 'account-auth-reset-password-reset___en'
| 'account-auth-reset-password-success___en'
| 'account-auth-set-password___en'
| 'account-auth-sign-up___en'
| 'account-auth-validate-email___en'
| 'account-auth-email-verify-id-hash___fr___default'
| 'account-auth-forgot-password___fr___default'
| 'account-auth-login___fr___default'
| 'account-auth-reset-password-email___fr___default'
| 'account-auth-reset-password-reset___fr___default'
| 'account-auth-reset-password-success___fr___default'
| 'account-auth-set-password___fr___default'
| 'account-auth-sign-up___fr___default'
| 'account-auth-validate-email___fr___default'
| 'account-dashboard-user-bookings___en'
| 'account-dashboard-user-profile___en'
| 'account-dashboard-user-bookings___fr___default'
| 'account-dashboard-user-profile___fr___default'
| 'account___en'
| 'account___fr___default'
| 'index___en'
| 'index___fr___default'
| 'index___fr'; |
Oh I see, it comes from |
For the route name, the only thing that I can rely on checking is keeping the |
Well since the |
I have not read your sources yet so maybe this is a wrong idea but my guess is that you exclude the i18n siblings from the generation, keeping only one route per page. Maybe then before converting this route's name to a type you could |
Although this might not be very robust since EDIT: Sent a PR of how I believe this could be done, feel free to improve on that (or ask me to improve on it) |
The separator should not be a problem as I can access the |
Thanks for your PR! I guess it should be a good idea to keep the |
I'm not sur I understand what you mean here. |
I will show a simple exemple In means transform this:
Into this
|
You can test it on commit: f02f7cb |
It's working ! 🥳 |
@Jassmin586 Could you create an another issue for this? I think this one may be too clutered already 😂 |
https://v8.i18n.nuxtjs.org/
The text was updated successfully, but these errors were encountered: