为什么我的组件不显示使用反应?(why my component is not display using react?)

编程入门 行业动态 更新时间:2024-10-28 17:14:45
为什么我的组件不显示使用反应?(why my component is not display using react?)

我试图显示一个react-component 。我添加了一些路由mechanism但它不显示我的组件。 这是我的代码

https://codesandbox.io/s/WnJl4DKOJ

import React from 'react'; import {Route} from 'react-router-dom'; import Hello from '../Hello'; const Routers = ()=> ( <Route exact path="/" component={Hello}></Route> ) export default Routers;

Index.js

import React from 'react'; import { render } from 'react-dom'; import {Router } from 'react-router-dom'; import createHistory from 'history/createBrowserHistory'; import Routers from './router/router'; const history = createHistory(); render( <Router routes={Routers} history={history}></Router> , document.getElementById('root'));

I am trying to display a react-component .I added some routing mechanism .but it not display my component. here is my code

https://codesandbox.io/s/WnJl4DKOJ

import React from 'react'; import {Route} from 'react-router-dom'; import Hello from '../Hello'; const Routers = ()=> ( <Route exact path="/" component={Hello}></Route> ) export default Routers;

Index.js

import React from 'react'; import { render } from 'react-dom'; import {Router } from 'react-router-dom'; import createHistory from 'history/createBrowserHistory'; import Routers from './router/router'; const history = createHistory(); render( <Router routes={Routers} history={history}></Router> , document.getElementById('root'));

最满意答案

您没有正确使用<Router /> 。 使<Routers />成为<Router /> 。

在您的示例中,将<Router routes={Routers} history={history}></Router>更改为:

<Router history={history}> <Routers /> </Router>

You're not using the <Router /> properly. Make your <Routers /> a child of <Router />.

In your example, change <Router routes={Routers} history={history}></Router> to:

<Router history={history}> <Routers /> </Router>

更多推荐

本文发布于:2023-07-30 13:46:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1337906.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:组件   component   react   display

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!