Link to master branch should not be internal #86
Comments
Thanks for the notice. Excuse my ignorance of React but I don't understand why Linking is so hard and error prone in our code base. Why can't use just use |
You're welcome. :) Honestly, I mainly use Vue so I don't have a good answer for you. ;) |
Its funny how the simplest things get super complicated in React 🤦♂️. If we use Instead of using The issue we have run into multiple times is that we try to navigate to external URL's using the internal linking from react-router. This because we try to push a url from a different origin onto the navigator.history (which is not allowed), so instead we get routed to We cant use In short: The reason for these issues is that I had to move like 90 We can either keep it the way it is and not make any more mistakes or make a custom link component that determines internally if it is a internal or external link and automatically uses the correct tag and correct styling - we would need versions for at least the material-ui Link and Button component. This way we could even add a little 'external' pictogram to external links. Up to you. |
I like @lucacasonato proposal to make the make a custom link component that determines internally if it is a internal or external link and automatically uses the correct tag and correct styling and avoid future errors here's a possible solution import React from "react";
import { HashLink, HashLinkProps } from "react-router-hash-link";
import { Link as MaterialLink } from "@material-ui/core";
const InternalLink = React.forwardRef((props: HashLinkProps, ref) => (
<HashLink {...props} />
));
export const Link = (props) => {
if (props.to.indexOf("://")=== -1) {
return <MaterialLink component={InternalLink} {...props}/>
} else {
return <MaterialLink {...props} component="a" href={props.to} />
}
} then usage is really simple import React from "react";
import { Link } from "./Links";
export const RandomComponent = (props) => {
<>
<Link to="/benchmarks">Styled Link</Link>
<Link to="https://github.com/denoland/deno">master branch</Link>
</>
} |
Are we good to close this issue? |
Yep - thanks @josephsintum |
Clicking the "master branch" link in the Benchmarks page treats the link as a route:
https://deno.land/https://github.com/denoland/deno
.I think this should be an
href
instead.https://github.com/denoland/deno_website2/blob/d0b37acea76c2f80866d99a4d89859b7bc26981a/src/Benchmarks.tsx#L124
The text was updated successfully, but these errors were encountered: