Search code examples
reactjsreact-router-dom

react app reloads when changing page within the app


My react app work fine in dev mode, but as soon as I change page the app reloads and in production mode it doesn't work. It's because the app reloads and it's okay in dev mode, but not in production mode

I use react-router-dom and I have tried changing the path without result.

I have made it in codesandbox.io here, it works but it still reloads the app and I can't see what's wrong

EDIT:

it's all under cv because it's going to be in a folder called cv (cv == resume) like this => http://firstname.lastname.com/cv


Solution

  • Try this in your navbar:

    import {Link} from 'react-router-dom';
    ...
    
    return (
        <StyledTypo textAlign="center" key={p.name} component="a" href={p.link}>
          <Link to={p.link}>
            <MenuItem onClick={handleCloseNavMenu}>{p.name}</MenuItem>
          </Link>
        </StyledTypo>