简体   繁体   中英

React-router-dom with Material-ui working but not mounting components

I'm working on this project: https://codesandbox.io/s/trusting-frog-089l2 My goal is to (as react-router-dom is supposed to work) navigate among various components using the Material-UI buttons on top. Only problem is, while the router works (I can see the mountpoint changing on the address bar), the right component does not get mounted. Does anyone know how to solve this?

 path='/studio/'

should be replaced with

path='/studio'

and also u should change the first route to have exact prop and remove it from the rest of the Route components

this is how your switch should look like:

<Switch>
     <Route exact path="/" component={Home} />
     <Route path="/studio" component={Studio} />
     <Route path="/stanzino" component={Stanzino} />
     <Route path="/affitti" component={Affitti} />
     <Redirect to="/" />
</Switch>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM