Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

139
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!