fridays / next-routes

Universal dynamic routes for Next.js
MIT License
2.47k stars 230 forks source link

Suggest to have `Link` and `Router` to be accessed by singleton #63

Closed mocheng closed 1 year ago

mocheng commented 7 years ago

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.

fridays commented 7 years ago

Thanks for your suggestion. It totally makes sense, I'll look into it!

mocheng commented 7 years ago

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.

jaydenseric commented 6 years ago

Pretty please. I want to publish a package compatible with next-routes out of the box.

connor-baer commented 6 years ago

@fridays I'd be happy to give this a shot and make a PR. Any tips or pointers before I get started?

RobertB4 commented 6 years ago

Is anyone still working on this? I'd love to have this.