Next-routes: Suggest to have `Link` and `Router` to be accessed by singleton

Created on 4 Jul 2017  路  5Comments  路  Source: fridays/next-routes

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.

Most helpful comment

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

All 5 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bliitzkrieg picture bliitzkrieg  路  4Comments

khankuan picture khankuan  路  7Comments

baires picture baires  路  6Comments

arefaslani picture arefaslani  路  3Comments

yves-s picture yves-s  路  4Comments