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
[TypeScript] LocaleRoute should return Location #776
Comments
nuxt-i18n doc is referring to |
For reference: https://github.com/vuejs/vue-router/blob/f0d9c2d93cf06b5b2202bd77df6281cf47970b20/types/router.d.ts#L138-L158 I suppose it should work to just change the type. The object will still technically be a route and will potentially contain some extra properties but that should hopefully not cause any issues. |
Event though the result is actually a route object, the point of localeRoute is to return something that can be passed to VueRouter.push() and that needs to be a Location object. Location is basically a subset of Route plus some optional properties so treating Route as Location should be fine. Resolves #776
Event though the result is actually a route object, the point of localeRoute is to return something that can be passed to VueRouter.push() and that needs to be a Location object. Location is basically a subset of Route plus some optional properties so treating Route as Location should be fine. Resolves #776
That got accidentally reverted during types refactoring. But now I'm having seconds thoughts about whether I should change it. The method is called localeRoute and it does return a But at the same time, it does make it inconvenient to use with |
@rchl I am not sure what are all the use cases for this function but for me so far I only use it primarily with localeRoute('myroute') // returns a Route
localeRoute('myroute').toRawLocation() // return a RawLocation Currently, I am creating my own types and importing them: // types taken from vue-router types https://github.com/vuejs/vue-router/blob/dev/types/router.d.ts#L188
// this is needed until this is fixed https://github.com/nuxt-community/i18n-module/issues/776#issuecomment-813201177
type Dictionary<T> = { [key: string]: T };
export interface Location {
name?: string;
path?: string;
hash?: string;
query?: Dictionary<string | (string | null)[] | null | undefined>;
params?: Dictionary<string>;
append?: boolean;
replace?: boolean;
} And use as such: this.$router.replace(this.localeRoute('thankyou') as Location); |
Changing the return type to |
Changed my mind. Leaving |
The intention of `localeRoute` was that it's used within `$route.push` call. The issue with that was that `localeRoute` returned `Route` while `push` expects `Location`. Changing the return type to `Location` while returning the route object would be wrong so instead added a new API that returns `Location` and left `localeRoute` to return `Route`. Fixes #776
Version
nuxt-i18n: 6.12.2
nuxt: 2.13.1
What is the problem ?
From vue-router type definitions:
push(location: RawLocation): Promise<Route>
replace(location: RawLocation): Promise<Route>
Those methods expect
type RawLocation = string | Location
but localeRoute from nuxt-i18n returnsRoute
object which is slightly different fromLocation
Solution expected
localeRoute(route: RawLocation, locale?: string): Route | undefined
localeRoute(route: RawLocation, locale?: string): Location | undefined
The text was updated successfully, but these errors were encountered: