3 ms·
I placed their Link component within a polymorphic wrapper which could switch between Link and plain anchor elements depending on the props given. The typing w
by steve_adams_86 3y ago
I placed their Link component within a polymorphic wrapper which could switch between Link and plain anchor elements depending on the props given. The typing was gnarly, but it worked well. By default it would be a Link as I recall, but things like a non-relative href or use=“a” props would swap it for an anchor. And maybe other things, I’m not sure. It would reject Link props if it knew it was using an anchor element, though.
I’m ashamed to say this took way too long to get working nicely. It was worth it because our linting otherwise went crazy over misuse of Link and anchor, and people on the team weren’t respecting it. This made it so we could say “only use Link” and make it easy for that to be accomplished.
Trust me, it’s way easier to get stuff done with Next :)
Once you get past the day or three spent making it so links do what you wish they did… And you discover it handles cache headers differently than it’s supposed to… And middleware doesn’t work in several contexts with no explanation… And on and on.
- lobsterthief 3y agoThis is also how I did it—also played nicely with ensuring MuiLink always get used on our MUI site.