【发布时间】:2020-04-03 03:19:06
【问题描述】:
您好,我有一个带有工具栏和按钮的应用栏
const AppRouter = () => (
<BrowserRouter>
<div>
<Header/>
<Navigation/>
<Switch>
<Route path="/" component={LandingPage} exact={true} />
<Route path="/xd" component={About} exact={true} />
<Route component={NotFoundPage} />
</Switch>
</div>
</BrowserRouter>
);
这是我的路:
<Route path="/xd" component={About} exact={true}/>
这是我的导航栏:
export default function Navigation() {
const classes = useStyles();
return (
<AppBar position="static" className={classes.appBar} >
<Container maxWidth="lg">
<Toolbar >
<Link to="/xd">
<Button className={classes.button} variant="raised" disableFocusRipple="false" disableRipple="false" centerRipple="false" color="secondary">
Home
</Button>
</Link>
<Button className={classes.button} variant="raised" disableFocusRipple="false" disableRipple="false" centerRipple="false" color="secondary">
Home
</Button>
<Button className={classes.button} variant="raised" disableFocusRipple="false" disableRipple="false" centerRipple="false" color="secondary">
Home
</Button>
<Button className={classes.button} variant="raised" disableFocusRipple="false" disableRipple="false" centerRipple="false" color="secondary">
Home
</Button>
</Toolbar>
</Container>
</AppBar>
);
}
当我单击其中一个按钮时,我只想更新内容容器 不知道我说的对不对
【问题讨论】:
-
将这些按钮包装在
Link组件中应该具有您想要的效果。这不工作吗? -
不是,我也不知道为什么:(
-
所以要确认一下,如果您在路径
"/"上并单击包裹在<Link to="/xd">中的第一个按钮组件 - 您的路径不会更改为"/xd"? -
是的,不要更改为 /xd
-
而且我的路线是正常的,我认为是我的导航栏有问题
标签: reactjs react-router material-ui