Declarative Routes for NextJS and React-Router: DRY Routing

  Рет қаралды 26,930

Jack Herrington

Jack Herrington

Күн бұрын

Пікірлер: 131
@grugbrain
@grugbrain 6 ай бұрын
You are the tech consultant of my company. 🤣
@josiahayres737
@josiahayres737 6 ай бұрын
I did not realise how much react routing sucked until I watched this video, I have to try this immediately. Calling out that you can incrementally adopt is what really sold me 🔥
@airixxxx
@airixxxx 6 ай бұрын
This is not React, it's Next. If you are using just React try Tanstack Router.
@eljaz00
@eljaz00 6 ай бұрын
Very elegant solution. Simple yet powerful.
@rogerscript
@rogerscript 5 ай бұрын
As usual, every video from you is awesome, I become a better developer every week thank to your channel, I really appreciate your work.
@mattwooddc
@mattwooddc 6 ай бұрын
Awesome video, Jack. Thank you!
@alexleung842
@alexleung842 6 ай бұрын
Nice. I'm surprised this doesn't exist already
@jherr
@jherr 6 ай бұрын
Right?!?
@anonypoke7486
@anonypoke7486 6 ай бұрын
You are a godsend in the community
@highrankin
@highrankin 6 ай бұрын
This looks great. Thank you!
@codewithguillaume
@codewithguillaume 6 ай бұрын
Ver nice, this is a real new approach right?! I like it!
@jherr
@jherr 6 ай бұрын
Kinda? It's built on top of what Flightcontrol did, but substantially improved. The scanner/builder is new, the whole API wrapping system is new, and the support for other types of routers is new. The React-Router support has some crazy hierarchich TypeScript generics in it that were fun to figure out. I should do a video on that. Arguably the React-Router implementation is even cooler since you can just change an entry in a table and all the routes change automagically. I don't know, or really even think, that this will be the end solution in this space. I just wanted to push the ball forward a little to see where other folks take it.
@sebastianlpoliak
@sebastianlpoliak 6 ай бұрын
WOooo amazing!! looking forward to check it
@Noam-Bahar
@Noam-Bahar 3 ай бұрын
This is AWESOME!!!
@jackn
@jackn 6 ай бұрын
top tier content. who even needs trpc or tanstack router anymore
@vty4261
@vty4261 6 ай бұрын
is that a joke?
@jackn
@jackn 6 ай бұрын
​@@vty4261no. TS has enough features on its own to be a type-safety contract generator. both trpc and ts-router are basically just doing the same thing with more complexity
@Osirisdigitalagency
@Osirisdigitalagency 6 ай бұрын
@@vty4261it definitely is cos wtf? Did he really said Tanstack for what?
@Royalettus
@Royalettus 6 ай бұрын
Wtf you mean??
@jackn
@jackn 6 ай бұрын
​@@Osirisdigitalagency it's not a joke, this is basically all tanstack router and trpc are doing is generating typescript contracts. they basically serve no other purpose than what was shown in the video if you can achieve this with plain TS why would you need a library for it
@elldy001
@elldy001 6 ай бұрын
Really nice solution, I will give it a try! Thank you, great work here 👍
@VincentFulco
@VincentFulco 6 ай бұрын
Awesome, looking forward to digging in...
@raphauy
@raphauy 6 ай бұрын
Thank you Jack!
@tidb1ts
@tidb1ts 6 ай бұрын
I am looking to do the same thing for remix! Awesome video as always!
@jherr
@jherr 6 ай бұрын
Feel free to jump in and contribute. There is a React-Router version there already, but it only works with the routes object declaration usage of React Router. So we'd need a version that would work with Remix's file routing. There are just so many variations of router setup out there.
@paweciosek489
@paweciosek489 6 ай бұрын
Great content! 👏👏 thank you! 🙏
@AdamM
@AdamM 6 ай бұрын
Really nice! Thanks
@rajthapa9006
@rajthapa9006 6 ай бұрын
Looks cool, will try it in my next todo app
@grugbrain
@grugbrain 6 ай бұрын
Awsome!! I need this in my app. I am done writing links everywhere.
@dahermora5976
@dahermora5976 6 ай бұрын
This declarative routing really takes any project to the next level! I have a question about the example using getPokemonSearchAPI. Shouldn’t we first validate the backend response using zod’s parse or safeParse to prevent any backend model changes from breaking our application? Thank you!
@ilkou
@ilkou 6 ай бұрын
this is VERY useful 🙌🏼🙌🏼🙌🏼
@joseandkris
@joseandkris 6 ай бұрын
This is a really good idea. Taking this for my projects ❤
@matematicafacile8107
@matematicafacile8107 4 ай бұрын
Hi Jack, thank you a lot for the effort you put in the channel. It helps a lot of people grow and that so valuable. I have a question... is there a way to handle catch all routes too? Thanks again|
@panteliselef239
@panteliselef239 6 ай бұрын
That's actually very interesting
@anshab454
@anshab454 Ай бұрын
Nice approach, thanks! What about dynamic routes? when I need to use same routes as Link in one place and in route.push() in other?
@yogeshvanzara5553
@yogeshvanzara5553 6 ай бұрын
Great as always ❤.
@eliuddyn
@eliuddyn 6 ай бұрын
Amazing 🔥🔥
@lcarv20
@lcarv20 6 ай бұрын
I know it’s zoomed but your terminal looks like a pack of m&ms. Nice video btw 🎉
@fullstackcoder1181
@fullstackcoder1181 6 ай бұрын
That’s another perfect video 🎉
@airixxxx
@airixxxx 6 ай бұрын
I've always done that by myself on my projects, it's one of the reasons I don't like Next directory based router. In the React standalone days, I would create all the routing from an constant object. If one route needed to change you only had to change that object, with Next you can't do that, you need to change the names and location of folders and in the code as well.
@xorlop
@xorlop 6 ай бұрын
Dang this really is cool.
@aveshlutchman8573
@aveshlutchman8573 6 ай бұрын
Ok, this is dope. The one thing that I would've preferred is if all the links were exported from one object. So something like `Link.Home` and `Link.Search` while the APIs would be something like `API.Search` and `API.Edit`, that way everything feels a bit more centralized
@jherr
@jherr 6 ай бұрын
Hmmm... Could be a cool option.
@Vir7uaLGameplays
@Vir7uaLGameplays 6 ай бұрын
I'll start using this on my app right a way thanks! 🎉
@GrigorMinasyan
@GrigorMinasyan 6 ай бұрын
This is awesome! But one thing I’m thinking is that generally the routing doesn’t need to change often on the app, and if it does then imo it’s a bigger issue with the application
@jherr
@jherr 6 ай бұрын
In evolved apps I think you are right. In early apps for small teams this could be a real ass-saver.
@fernandosalazar8814
@fernandosalazar8814 6 ай бұрын
Looking forward to contribute! Which repo is it? Found the demo repo but not the package one 😅
@MrJulzies
@MrJulzies 6 ай бұрын
This reminds me of the work done by ethan on next-typesafe-url ( cant paste links ) :( ! Super awesome stuff and works pretty well in my projects to solve the same problem :)
@Royalettus
@Royalettus 6 ай бұрын
You are awesome 👌
@djibrilm__-
@djibrilm__- 6 ай бұрын
Any vidoe or course on how we can build such thing it doesn't have to be a strong as the original library... That can be the ultimate senior front end video ever posted on KZbin Whag a flex having such project sitting on my portfolio. Hope my comment get noticed by the author.
@iamcasted
@iamcasted 6 ай бұрын
I used to do an object in a config file which contained all routes
@coherentpanda7115
@coherentpanda7115 6 ай бұрын
That's how we do it,, has always worked well. This package does neat things, I think it would be useful for taking over maintenance of an app that has all of the links hardcoded. Not sure I'd ever use it in a new project, though.
@jsmnd23
@jsmnd23 6 ай бұрын
Awesome! Can you please make a video about Vercel's Generative UI. 🙏
@anstbt
@anstbt 4 ай бұрын
great voice i like it , thanks
@ricardojorgealmeidarocha4880
@ricardojorgealmeidarocha4880 6 ай бұрын
Do you have any video with your vscode theme, icons, font, terminal, etc. ?
@ThEGeEeK
@ThEGeEeK 6 ай бұрын
He is GOLD 🪙
@xela92
@xela92 6 ай бұрын
That's a really nice system, I was curious to dig into the project's code to better understand it but it seems you don't ship the non uglified code of declarative-router, that's a curious choice..? 🤔
@jherr
@jherr 6 ай бұрын
Here is a link to the repo: github.com/ProNextJS/declarative-routing
@xela92
@xela92 6 ай бұрын
@@jherr thanks, totally missed that 😅👍
@mikimaine
@mikimaine 6 ай бұрын
🔥LGTM
@dontwanttousemyrealnametol6765
@dontwanttousemyrealnametol6765 6 ай бұрын
what's wrong with a recursive sed -i substitute command? It wil take much longer to figure out what's going on if I find this declarative routing stuff in an old project two years from now... AND to remember to have to run some binary with a specific pnpm version and AAARGH...
@jherr
@jherr 6 ай бұрын
Well, it's not a binary, and all of the source is in your source, but if you don't want to use it that's totally fine by me.
@dontwanttousemyrealnametol6765
@dontwanttousemyrealnametol6765 6 ай бұрын
​@@jherr thanks... sorry I had a stressful day and may have overreacted
@mzerone-g6m
@mzerone-g6m 6 ай бұрын
I think it is awesome
@zanzaraloggan3713
@zanzaraloggan3713 6 ай бұрын
I usually put my routes in variables... then I do just const userRoute = 'user/:id'; and then userRoute.replace(':id', user.id)
@rand0mtv660
@rand0mtv660 6 ай бұрын
Why not create a function that returns the string? const createUserRoute = (id) => `user/${id}`;? Seems more sensible compared to userRoute.replace because you don't have to know what specific string you have to replace, you just pass in arguments.
@hassan.tl94
@hassan.tl94 6 ай бұрын
Hi Jack, great tutorial, one thing I noticed the package doesn't take into account is folder groups. I have grouped features of the app under folder like `(marketing)` or `(users)` under app folder and the routes created are `/(marketing)/(home)` even though it should be `/` - so perhaps ignoring the folder groups would be a great addition to the package
@jherr
@jherr 6 ай бұрын
Feel free to contribute that. Or add an issue and someone else might pick that up. I'll definitely be working on this more, but at the moment the course is my daily top priority.
@hassan.tl94
@hassan.tl94 6 ай бұрын
@@jherr yes I can look into that, I couldn't find the repository for declarative routing - can you provide the link?
@jherr
@jherr 6 ай бұрын
@@hassan.tl94 github.com/ProNextJS/declarative-routing
@ThEldeRS
@ThEldeRS 6 ай бұрын
This is pretty cool! How do you handle error handling with API routes?
@jherr
@jherr 6 ай бұрын
It's a promise, you can do a catch on it to catch the errors.
@TianYuanEX
@TianYuanEX 6 ай бұрын
I think something like this already exists for Next.js, IIRC it's called next-typesafe-url. As for pure React, tanstack router is (IMO) a more reliable option.
@jherr
@jherr 6 ай бұрын
Interesting, I still have to manage that URL as a string every time I use the link though. Plus from the little video attached to the github page the resultant code to build the href is pretty long. Also, it only handles page routes and not API routes.
@TianYuanEX
@TianYuanEX 6 ай бұрын
@@jherr Fair enough
@incarnateTheGreat
@incarnateTheGreat 6 ай бұрын
Thanks for this. May I ask how you customized your Shell? Thanks!
@jherr
@jherr 6 ай бұрын
It's oh-my-posh on top of oh-my-zsh.
@incarnateTheGreat
@incarnateTheGreat 6 ай бұрын
@@jherr Thanks!
@untlsn
@untlsn 6 ай бұрын
I prefer to use function that return url So if I need to give this url to custom component with href or to navigate, I can
@jherr
@jherr 6 ай бұрын
Then just call the function directly and it will return the URL, as shown in the video.
@tunamusic2314
@tunamusic2314 3 ай бұрын
which extension to edit multiple line >
@kasujjamuhammed663
@kasujjamuhammed663 6 ай бұрын
This is great work. Can it be used with tanstack-router with vite
@jherr
@jherr 6 ай бұрын
With Vite you can use React-Router. Tanstack is a little tricker, I would need to work with that team to figure out integration into TSR and their Vite plugin.
@kasujjamuhammed663
@kasujjamuhammed663 6 ай бұрын
@@jherr thanks please
@kasujjamuhammed663
@kasujjamuhammed663 6 ай бұрын
@jherr I will check it out with react-router
@Anas_Alaqeel
@Anas_Alaqeel 6 ай бұрын
The video is nice, but I don't see the need for the library. Typically, I store the endpoints in a standard JSON file and import them wherever necessary. If I need to change an endpoint, I only update the JSON file, and the changes are reflected everywhere. This keeps the syntax of routing components consistent and avoids confusion for anyone who works on the project later.
@garasipemula
@garasipemula 6 ай бұрын
I like it, I will try it in my project, but can it be used on server actions?
@jherr
@jherr 6 ай бұрын
I don't see why you couldn't use it in a server action, but server actions don't need them since NextJS handle the routing on that automatically.
@garasipemula
@garasipemula 6 ай бұрын
Oh I get it 🤣
@Vir7uaLGameplays
@Vir7uaLGameplays 6 ай бұрын
Hi Jack, my index.ts is not correctly making the imports because it's using backslashes instead of forward slashes.
@jherr
@jherr 6 ай бұрын
Are you on windows?
@Vir7uaLGameplays
@Vir7uaLGameplays 6 ай бұрын
@@jherr yes I am Jack
@kinofan_org
@kinofan_org 6 ай бұрын
Links from the "Installation" section of NPM lead to a 404 page.
@dylanstephens1222
@dylanstephens1222 6 ай бұрын
Sorry to highjack this video, Jack. I've got a request that I'm sure you're capable of answering. With TRPC and Prisma, do you have a recommendation on how to do multivariant products design, such as size, color, or any other custom variant group? I'm struggling a lot with how to handle it when not having concrete tables such as size, color, etc. I've looked into the EAV design theory, but can't seem to apply it with "pivot tables" using Prisma.
@jherr
@jherr 6 ай бұрын
Feel free to jump on the Discord server and ask your question there. Please read and follow the #rules before posting, it's an all volunteer support service.
@Hacking-Kitten
@Hacking-Kitten 6 ай бұрын
if you have to change your routing at a point where you have tons of references you have a problem anyways.. breaking links on the customer side
@АлександрГерасимов-с3щ
@АлександрГерасимов-с3щ 6 ай бұрын
What is optimal way to keep main process and watchers from all different tools active without opening 100500 terminals? Can you make video on this topic?
@jherr
@jherr 6 ай бұрын
Use the concurrently library.
@Mong3
@Mong3 6 ай бұрын
Where is the repository link for this project?
@jherr
@jherr 6 ай бұрын
github.com/ProNextJS/declarative-routing
@chriswatts923
@chriswatts923 6 ай бұрын
I hate this in react, magic strings everywhere.. I just wanted the native router to support route tags so you define route strings once but links can point to route tags.. good alternative but think the main Devs should have done a lot better
@reeteshvirous1359
@reeteshvirous1359 6 ай бұрын
Its failing with NextJS latest version 14.2
@SanderCokart
@SanderCokart 6 ай бұрын
How can this use dot notation in a server component wtf?
@jherr
@jherr 6 ай бұрын
Crap, that's true. I forgot about that.
@SanderCokart
@SanderCokart 6 ай бұрын
@@jherr so how is your example not crashing? 😅
@jherr
@jherr 6 ай бұрын
@@SanderCokart I've forgotten the constraint. It might fail on build. I'll check it out. Either way, you can fall back on using the string variant. Or... you can change the code so that the component is the primary export, so it would be `` instead. The code is just copied into your repo like shadcn.
@SanderCokart
@SanderCokart 6 ай бұрын
@@jherr it should've failed on dev too.
@pmioduszewski
@pmioduszewski 5 ай бұрын
Dr. Build
@danielfrey1359
@danielfrey1359 6 ай бұрын
how about using it with Nx monorepo?
@jherr
@jherr 6 ай бұрын
I don't see why that would be a problem, you'd just have to launch it as in the context of the repo. It just runs `pnpm add` (or whatever your package manager is) so hopefully that works. I don't like that NX removes package.jsons.
@danielfrey1359
@danielfrey1359 6 ай бұрын
I am gonna give it a go, keep you posted
@АлександрГерасимов-с3щ
@АлександрГерасимов-с3щ 6 ай бұрын
Who is your favorite pokemon and what makes it special?
@jherr
@jherr 6 ай бұрын
Gumshoos. He's terrible and he looks a little like me.
@hasst9261
@hasst9261 6 ай бұрын
Rly you didn't left the link on NPM, why?
@jherr
@jherr 6 ай бұрын
Good point: www.npmjs.com/package/declarative-routing
@hasst9261
@hasst9261 6 ай бұрын
@@jherr TY. I meant about description below the video Have a good one!
@jherr
@jherr 6 ай бұрын
I added it there too ty
@zbynekriha
@zbynekriha 6 ай бұрын
i am missing readme and examples
@Joshua-dc4un
@Joshua-dc4un 6 ай бұрын
The validation is a bit unnecessary given it's used in the same application. Typescript covers most of that use case
@jherr
@jherr 6 ай бұрын
Which validation part?
@avishekdas4947
@avishekdas4947 6 ай бұрын
Your course status?
@jherr
@jherr 6 ай бұрын
Going really good. Release late this month or early next. I'm really proud of it.
@avishekdas4947
@avishekdas4947 6 ай бұрын
@@jherr That's really exciting!
@engine_man
@engine_man 6 ай бұрын
This is cool, but for the love of god , do not add this to your company’s nextjs project. It’s like react devs are plagued with the curse of abstracting everything, on top of that this adds another build step and another dependency to the mammoth that is the node modules folder.
@jherr
@jherr 6 ай бұрын
Except that this doesn't actually add to the node_modules folder beyond zod and and the URL parser.
@engine_man
@engine_man 6 ай бұрын
@@jherr happy to be proven wrong.
@Its-InderjeetSinghGill
@Its-InderjeetSinghGill 6 ай бұрын
Awesome solution Jack, I really appreciate you hard work🫡
Finally Fix Your Issues With JS/React Memory Management 😤
20:13
Jack Herrington
Рет қаралды 86 М.
World‘s Strongest Man VS Apple
01:00
Browney
Рет қаралды 66 МЛН
Flipping Robot vs Heavier And Heavier Objects
00:34
Mark Rober
Рет қаралды 59 МЛН
I Waited 3 Years For This Router. It STILL Blew My Mind.
21:30
Theo - t3․gg
Рет қаралды 101 М.
Are You In A React Cult?
13:27
Jack Herrington
Рет қаралды 30 М.
Payload: The Complete Backend for NextJS
27:10
Jack Herrington
Рет қаралды 43 М.
Why I don't use React-Query and tRPC in Next.js
18:58
ByteGrad
Рет қаралды 92 М.
How I Write Clean Code in React
16:36
Cosden Solutions
Рет қаралды 31 М.
Next.js App Router: Routing, Data Fetching, Caching
14:32
Vercel
Рет қаралды 324 М.
Why Signals Are Better Than React Hooks
16:30
Web Dev Simplified
Рет қаралды 481 М.
React Hook Form & React 19 Form Actions, The Right Way
16:08
Jack Herrington
Рет қаралды 54 М.