I found that next-routes API is not friendly.
In next.js, each component could just depend on next/link. So, component can reside in a standalone repo and published as npm package. However, when utilizing next-routes, I have to import Link from routes.js file specific to given application. As a result, there is no way to create a standalone component to be shared.
import {Link} from 'path/to/routes';
How about making Link and Router accessible by singleton object in next-routes? Like this
import {Link} from 'next-routes/link';
import {Router} from 'next-routes/router';
Internally, when next-routes is executed to create instance, the instance is saved as singleton to be exposed by next-routes/link and next-routes/router.
Thanks for your suggestion. It totally makes sense, I'll look into it!
For the time being, I just created a wrapper component of Link from next-routes. That wrapper renders Link from a singleton instance created by next-routes at runtime. It works in some way, but the wrapper-over-wrapper-over-next-link may be expensive.
Pretty please. I want to publish a package compatible with next-routes out of the box.
@fridays I'd be happy to give this a shot and make a PR. Any tips or pointers before I get started?
Is anyone still working on this? I'd love to have this.
Most helpful comment
Thanks for your suggestion. It totally makes sense, I'll look into it!