thomhos / next-routing-tools

Easily configure dynamic routes for Next.js
3 stars 0 forks source link

Ahoy! Need a hand? #1

Open jthegedus opened 6 years ago

jthegedus commented 6 years ago

Hey @thomhos , I use Next.js with types daily and am interested in this package. If you need a hand getting more features implemented or writing a next-routes migration guide (people will ask for one) then I'm happy to help.

thomhos commented 6 years ago

hey there!

I would very much appreciate some help on this one :)

There are a few things which still need to be sorted out if we want to support most usecases. Most importantly passing href objects link the original next/Link component. I'll make some issues for these things so we can keep track of them.

Do you have anything you're missing or want to see changed?

Cheers!

jthegedus commented 6 years ago

Nothing missing in particular. The discussion on Zeit Slack was about next-routes not having as active a maintenance as ideal. Since there's a barrier to contributions on that package this one seemed appropriate to look into and help move along where possible.

Things that make this appealing over the other:

In general, the tech stacks I use are typed except for the Next.js ecosystem. Replacing a community typed package with a natively typed package is worth the effort IMO.

As for helping, I'm not particularly versed in web routing, but happy to learn and contribute where I can. I'll look into the source here and at next-routes to see how things work in each place to get an understanding. Any resources on web routing to accelerate my learning would be much appreciated, but I think reading source will do.

The package is named next-routing-tools, do you have things in mind for this package beyond feature parity with next-routes? (just curious)

As an aside, I'm on a bit of a mission to get the DefinitelyTyped Next.js types up to date with the current release, but I'm just getting started in the TS world, so if you have any advice or input, please check it out - https://github.com/DefinitelyTyped/DefinitelyTyped/pull/24231

thomhos commented 6 years ago

Sounds good :)

Those reasons were the main reason for me to write this lib for myself as well. I named it routing tools because I didn't want to call it next-router or something remotely 'official'. For that it would have to be adopted much more / be more completed I think.

In short, how this works is;

  1. define routes by creating new instances of the 'Route' class
  2. pass the routes and the app to a handler on the server (for now only express, but we can easily make more handlers for other libs), so the server finds a match, parses the params and then renders the app.
  3. create a route provider in the app, which uses context to pass the routes in the tree
  4. each link component can use context to look up if the url is an existing route, if so; transform the params to query params. if not leave it as it is.

For url matching we have the match-url function which returns a route instance if it finds a match. From that route instance we can then grab the parsed params, href etc.

Let me know if you run into issues or have any requests. I can probably work on it or give some pointers how to implement it.