Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

React Redirection Doesn't Work on Github Pages

In my main.js file, I have written the following code:

const Contact = styled(NavLink)`
color: ${props => props.theme.text};
position: absolute;
top: 2rem; 
right: calc(1rem + 2vw);
text-decoration: none;
z-index: 1;
`
<Contact target="_blank" to={{pathname: "mailto:email@gmail.com"}}>
            <motion.h2
            whileHover={{scale:1.1}}
            whileTap={{scale:0.9}}
            >

and it works alright on localhost. However, after I deployed the website on Github Pages, by clicking on the button, I get redirected to
https://username.github.io/webpage/#/mailto:email@gmail.com
Instead of
email@gmail.com

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

NavLink from react-router meant to route in a SPA.
Just use the ‘a’ tag for this

<a href="mailto:email@gmail.com">Email</a>

or you should try

<Contact target="_blank" to='#' 
      onClick={() => window.location = 'mailto:email@gmail.com'}
>
...
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading