question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Persistent Drawer links not working as expected with react-router-dom

See original GitHub issue

When mdc-web persistent drawer is used with react-router-dom (BrowserRouter), the links inside the drawer are losing SPA behavior. That is links the links (html <a>) inside the drawer are bypassing react-router, and making a fresh request to the server.

What MDC-Web Version are you using?

https://unpkg.com/material-components-web@latest/dist/material-components-web.css https://unpkg.com/material-components-web@latest/dist/material-components-web.js

What browser(s) is this bug affecting?

Chrome

Version 59.0.3071.115 (Official Build) (64-bit)

What OS are you using?

macos sierra, and windows 10.

What are the steps to reproduce the bug?

  1. npm install -g create-react-app
  2. git clone https://github.com/smandava/router-issue
  3. cd router-issue
  4. npm i
  5. npm start
  6. open http://localhost:3000 on your browser
  7. open developer tools and network tab
  8. click on About link, network tab shows about 12 requests made to the server to render the page (actual behaviour)

  1. open app.js in a text editor.
  2. replace BrowserRouter with HashRouter and save the file.
  3. open http://localhost:3000 on your browser
  4. open developer tools and network tab
  5. click on About link, you see the No network requests but the link is still functional. (expected behaviour).

What is the expected behavior?

Described in (12) above.

What is the actual behavior?

Described in (7) above.

Any other information you believe would be useful?

None.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
AustPcommented, Aug 16, 2017

I had this same issue. This is my workaround until something gets implemented:

if (!MDCTemporaryDrawer.prototype.getDefaultFoundation_) {
  MDCTemporaryDrawer.prototype.getDefaultFoundation_ = MDCTemporaryDrawer.prototype.getDefaultFoundation;
  MDCTemporaryDrawer.prototype.getDefaultFoundation = function() {
    const foundation = this.getDefaultFoundation_();

    foundation.drawerClickHandler_ = (e) => {
      if (e.target.tagName !== 'A') {
        e.stopPropagation();
      }
    };

    return foundation;
  };
}
0reactions
kfranqueirocommented, Dec 4, 2017

This has been fixed via 3e173e1ddc3bff5c7c9c2d794eeb36a9354ec98c (based on #1138), which refactors out the stopPropagation call.

Read more comments on GitHub >

github_iconTop Results From Across the Web

MUI Drawer not rendering with React-router-dom v6
So I configured in my index.js the different routes using react-router-dom@v6. I can access my pages by entering the link directly in the...
Read more >
Migrating to React Router v6: A complete guide
Migrate your React Router applications from v5 to v6 with this in-depth guide, including a review of additions and improvements from v5.
Read more >
Navigation in React App using React Router (v6)
Now run the application and navigate through the links and you should be able to see the appropriate components being rendered. Basic Routing....
Read more >
React & Material UI #21: Drawer & Drawer + React Router
In this video we go over:- The 3 Material UI Variants within React - MUI Drawer props- How the Drawer works with List...
Read more >
Material-UI Drawer + React Router Tutorial (Navigation in React)
Learn how to create a React application using Material-UI for style & react router to handle routing.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found