-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: use routes constant for all internal paths #1071
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
based
@evgenyboxer Have you looked into this? https://github.com/ckastbjerg/next-type-safe-routes Seems like it could get us most of the benefits without any of the maintenance. Also would get us type safety on params and stuff. Definitely curious to hear your thoughts. Let me know! |
Hey @tbezman That's absolutely the way to go, had no idea this existed. My only concern with this specific library is that it doesn't look widely used / maintained. I had a spin on it, and found a couple of issues -
Happy for you to play with this as well and let me know if you find success in using it. I really like the direction of this library, it is definitely an improvement over my solution. |
|
||
const moduleExports = { | ||
/** @type {import('next').NextConfig} */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This gives a nice autocomplete for next config options
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
YESSSSSS
module.exports = withSentryConfig(moduleExports, sentryWebpackPluginOptions); | ||
const plugins = [withRoutes, (config) => withSentryConfig(config, sentryWebpackPluginOptions)]; | ||
|
||
module.exports = () => plugins.reduce((config, plugin) => plugin(config), nextConfig); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Followed the thread here - cyrilwanner/next-compose-plugins#59
<ButtonLink href="#">primary</ButtonLink> | ||
<ButtonLink href="#" pending> | ||
<ButtonLink href={{ pathname: '/' }}>primary</ButtonLink> | ||
<ButtonLink href={{ pathname: '/' }} pending> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tbezman Would that work? or do we need a workaround here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem here
? { pathname: '/[username]', query: { username: admire.admirer.username } } | ||
: { pathname: '/' }; | ||
|
||
const admirerLink = route(admirerLinkRoute); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm using this pattern here since <Link
wants a Route
and AdmirerName
wants a string
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to me. Next 13 removes this double tag nonsense so we'll be able to just use the route!
|
||
export type InternalAnchorElementProps = Omit<AnchorElementProps, 'href'> & { | ||
href: Route; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tbezman I wasn't sure of a good name for this, so went with something generic (Elements.ts
) that could house similar types in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dig it.
|
||
const moduleExports = { | ||
/** @type {import('next').NextConfig} */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This gives us a new autocomplete for the config
Hopefully I've covered all instances of the internal paths! I've replaced them all with the routes constant.