Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

140
Visualizações
Cannot Link to part of page with MUI 5 Drawer

I'm simply trying to link to a specific part of my first page when the user clicks on the Shop button in the navigation Drawer but it doesn't do anything at all:

enter image description here

This is the code for the MUI 5 Drawer component:

    <Drawer
      anchor="left"
      open={open}
      onClose={() => setOpen(false)}
      PaperProps={{
        sx: {
          background: "linear-gradient(to top, #9C685B44, #9C685Bff)",
        },
      }}
    >
      <IconButton onClick={() => setOpen(false)}>
        <ChevronLeftIcon sx={{ color: "white" }} />
      </IconButton>
      <Divider />
      <List>
/////////////////////////////////
        <ListItem>
          <Button
            // Linking to Products Section
            href="#products"
            startIcon={<PhoneAndroidIcon />}
            sx={{
              color: "white",
              fontFamily: "Montserrat",
            }}
          >
            Shop
          </Button>
        </ListItem>
//////////////////////////////
        <ListItem>
          <Badge color="error" badgeContent={badgeNumber}>
            <Button
              startIcon={<ShoppingCartIcon />}
              sx={{
                color: "white",
                fontFamily: "Montserrat",
              }}
            >
              Cart
            </Button>
          </Badge>
        </ListItem>
      </List>
    </Drawer>

And in that respective section, I have added an id with the value of products to the container:

<Container maxWidth="xl" id="products">
   ...
</Container>

Even using the anchor tag results in the same issue.

Is there anyway to fix this?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can use scrollIntoView and History.pushState() to handle this. Remove the href from your Button component, and instead use its onClick method to call the following:

// id is your section names (e.g. 'products')
// url is optional, and if not specified, is set to the document's current URL

const onNavClick = (event, id, url) =>
{
    let element = document.getElementById(id)
    event.preventDefault()
    element.scrollIntoView()
    window.history.pushState(id, id, url)
}

There are various other options you can pass into scrollIntoView, and you can find out more about the available options by following the link above.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda