我导出了一个react js组件,但是当我启动应用程序时,它不会显示输出
嗨,我是新手编码和尝试构建React应用程序的新手。我只是创建一个名为login.js的React组件并将其导出为默认值并将其导入App.js,但是当我启动React App时,我用login.js编写的DIV并未在显示屏上显示。
login.js代码:
import React from 'react';
// import styled from 'styled-components';
const Login = ( props ) => {
return(
<div>hello world</div>
);
};
export default Login;
app.js代码:
import { BrowserRouter as Router, Routes, Route } from 'react-router-dom';
import './App.css';
import Login from './components/Login';
function App() {
return (
<div className="App">
<Router>
<Routes>
<Route exact path='/'>
<Login />
</Route>
</Routes>
</Router>
</div>
);
}
export default App;
我的应用程序输出: 在运行应用程序后输出
导出后,因为它显示了这一点: 证明该组件已导出
我尝试了很多方法,但没有任何工作。请帮助
Hi i am new in coding and trying to build a react app. I just create a react component named login.js and export it as default and import it in app.js, but as i start my react app the div that i written in login.js is not displaying on the display.
Login.js code:
import React from 'react';
// import styled from 'styled-components';
const Login = ( props ) => {
return(
<div>hello world</div>
);
};
export default Login;
App.js code:
import { BrowserRouter as Router, Routes, Route } from 'react-router-dom';
import './App.css';
import Login from './components/Login';
function App() {
return (
<div className="App">
<Router>
<Routes>
<Route exact path='/'>
<Login />
</Route>
</Routes>
</Router>
</div>
);
}
export default App;
my app output:
output after running the app
it is exported because it showing this :
proof that the component is exported
I tried so many ways but nothing worked. Plz help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如
React-Router-dom
的文档中,您需要将组件指定为名为element
的prop。在这里查看更多此处
As in the document of
react-router-dom
, you will need to specify your component to a prop namedelement
.See more here