Next-i18next: How to combine next-routes & next-i18next Link?

Created on 11 Mar 2019  路  8Comments  路  Source: isaachinman/next-i18next

Is your feature request related to a problem? Please describe.

Both next-routes and this lib provides a Link component in order to enable a better dev experience, the problem is how one should combine them together, the issue is that both Link components are using Next's Link component.

Describe the solution you'd like

Maybe it is better to expose As attribute so the component that will be rendered will be the next-routes Link component.

One would be able to create a Combining Link, something like that:

import Link as I18nLink from '../i18n';
import Link as RoutesLink from '../routes';

export Link = ({children, ...rest})  => (
   <I18nLink as={RoutesLink} {...rest}>{children}</I18nLink>
);

Maybe it should be the opposite, that nextRoutes Link component will expose that.

Most helpful comment

@weishiji next-routes allow you to pass Link Component & Router to the constructor, so, you can pass the next-i18next Link & Router to it.

Can you give me a demo? I do not understand how he did it

Yes,I got it
image

All 8 comments

Just from reading the sourceCode of NextRoutes, I've found that it allows to get an external Link & Router.

https://github.com/fridays/next-routes/blob/master/src/index.js#L11

Hi @felixmosh - it's not recommended to use next-routes in conjunction with next-i18next, or really to use next-routes in general.

@isaachinman why?
How would you generate dynamic pages?

You can check the docs section on custom routing. The next-routes implementation is problematic last I checked - you can search issues in the NextJs repo.

@isaachinman why?
How would you generate dynamic pages?

Finally, how did you resolve this question. It troubled me a long time.

@weishiji next-routes allow you to pass Link Component & Router to the constructor, so, you can pass the next-i18next Link & Router to it.

@weishiji next-routes allow you to pass Link Component & Router to the constructor, so, you can pass the next-i18next Link & Router to it.

Can you give me a demo? I do not understand how he did it

@weishiji next-routes allow you to pass Link Component & Router to the constructor, so, you can pass the next-i18next Link & Router to it.

Can you give me a demo? I do not understand how he did it

Yes,I got it
image

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dohomi picture dohomi  路  5Comments

isaachinman picture isaachinman  路  7Comments

andrenaught picture andrenaught  路  6Comments

slava-lu picture slava-lu  路  6Comments

dimensi picture dimensi  路  4Comments