Replies: 8 comments 16 replies
-
Yes yes yes! Looks awesome! |
Beta Was this translation helpful? Give feedback.
-
I think it would be great to expose a function to figure out if link is active. The |
Beta Was this translation helpful? Give feedback.
-
Great idea. Not so sure about the idea of including styling within the link component. Ideally we want to manage the link behaviour and stay out of styling. In fact we would probably want to delegate all styling to whatever system the user is using such as styled-components etc. I would vote for a render prop to manage active etc. <Link href={'/products/' + product.id} >
{({active}) => (
<MyStyledProductName active={active}>product.name</MyStyledProductName>
)}
</Link> |
Beta Was this translation helpful? Give feedback.
-
For the linking to external sites, it would be probably better to always render an anchor tag, for semantics and routing to work the hard way if the bundle is not finished loading/hydrating. Also, mailto addresses can also be |
Beta Was this translation helpful? Give feedback.
-
Perhaps these improvements could be proposed to be implemented in Next.js core |
Beta Was this translation helpful? Give feedback.
-
UpdateHere's a custom <Link page="/users/[id]" params={{ id: user.id }}>
{user.name}
</Link>
<Link page="/blog/[...slug]" params={{ slug: ['coffee', 'frenchpress'] }}>
View Here
</Link> It's a lot better than the default Next.js and could be a good option to add to Blitz. But I think only having a single What do y'all think? |
Beta Was this translation helpful? Give feedback.
-
Hello! I think providing our own Link component may not be the best solution. Next, React-Router and Reach Router already have theirs. I think having yet another Link API will be confusing for many users. But I think Blitz is in a unique position to solve the links problem. Unlike the routing libraries I mentioned, we have a build process to compile a Blitz app to a Next app. I think we could use that moment to transform plain I think this the best of both worlds. Users don't have another API to learn, they just write I think this would add more magic to the Blitz experience, just like importing backend functions in React. |
Beta Was this translation helpful? Give feedback.
-
Just as a reminder in case this gets implemented: Next.js' |
Beta Was this translation helpful? Give feedback.
-
Update 12/10/2020
<Link>
now works with justhref
and doesn't require theas
prop. You can also use it to link to external sites. But you still can't setclassName
oractiveClassName
to<Link>
.What do you want and why?
A new Link component that's much easier to use that the default Next.js Link!
The Next.jsLink
component is terribly cumbersome to use:You can't use this Link component to link to external sites.className
on<Link>
Proposal
I think this is the best option I've considered. It's quite natural and intuitive. And it doesn't require you to think about what the actual page is named.
Other Next.js link options will still be supported, like
replace
andscroll
Active Styles
By default, active styles are applied when
href === pathname
activeClassName: string
activeStyle
: a normal Reactstyle
object applied when the current link is activePartially Active
Sometimes you want a link to be active if there's a partial sub-match instead of a full path match. For this case, you can pass
partiallyActive={true}
This example link to
/products
will show as active when the current path is/products/1
.Linking to External Sites
We can support linking to other sites by rendering a plain
<a>
tag ifhref
includes a protocol (://
)Href as an Object
Same format as Next.js
Converting Next apps to Blitz apps
People with existing Next apps will be importing
Link
fromnext/link
, so this will continue to work as expected. But if they change to importLink
fromblitz
, then they will need to update the usage of Link. This could probably be done via a codemod.Implementation
This is complex to implement because we must compute a route manifest at build time and use that during runtime to map this api to what Next requires. But it's totally possible.
React.forwardRef
What do you all think about this? Any other rough spots with the Next.js Link that we can improve?
Similar discussion in the Next.js repo: vercel/next.js#8207
Beta Was this translation helpful? Give feedback.
All reactions