[英]Rendering two different components with Reactjs
I've 2 different components, and I would like to render them separately.我有 2 个不同的组件,我想分别渲染它们。 Logic is simple when user is logged in render 1st component , if it's not render default component .
当用户登录时,逻辑很简单渲染第一个组件,如果它不是渲染默认组件。
Please review my code, and help me with this, I'm not good at react, so please help me请检查我的代码,并帮助我解决这个问题,我不擅长反应,所以请帮助我
export default function App(props) {
const Authenticated = props.Authenticated
const RoutingCabinet = (
<React.Fragment>
<Header/>
<Switch>
<Route exact path = '/' component = { () => TempBody} />
<Route exact path = '/new' component = { () => <ResponsiveDrawer />}/>
</Switch>
<Footer/>
</React.Fragment>
);
const RoutingContent = (
<React.Fragment>
<Cabinet />
<Switch>
<Route exact path = '/user.test'component = { () => <div>Element</div> }/>
</Switch>
</React.Fragment>
);
return(
<ThemeProvider theme = {Theme}>
<BrowserRouter>
{
Authenticated
? RoutingCabinet
: RoutingContent
}
</BrowserRouter>
</ThemeProvider>
);
}
Currently I can see only RoutingCabinet目前我只能看到RoutingCabinet
Here is the index.js这是 index.js
ReactDOM.render(<App Authenticated = {false} />, document.getElementById('__body__', '__root__'));
I may be wrong here, but is <Cabinet />
the same as <RoutingCabinet />
?我在这里可能错了,但是
<Cabinet />
和<RoutingCabinet />
一样吗? If so, it might work ok.如果是这样,它可能工作正常。 The
<div>Element</div>
will be visible only if url matches user.test
. <div>Element</div>
只有在 url 匹配user.test
时才可见。 If you are on any other page, this won't be rendered, so it'll look like <RoutingCabinet />
is rendered, while in fact it's <RoutingContent />
, it just renders the same output.如果您在任何其他页面上,则不会呈现它,因此它看起来像
<RoutingCabinet />
被呈现,而实际上它是<RoutingContent />
,它只是呈现相同的 output。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.