React does not display the component when the reference is switched
-
I can't figure out why there's a reason in the syntax, or if the library is missing.
Here package.json
{ "name": "new-app", "version": "0.1.0", "private": true, "dependencies": { "@testing-library/jest-dom": "^5.14.1", "@testing-library/react": "^11.2.7", "@testing-library/user-event": "^12.8.3", "react": "^17.0.2", "react-dom": "^17.0.2", "react-router-dom": "^6.0.0", "react-scripts": "4.0.3", "web-vitals": "^1.1.2" }, "scripts": { "start": "react-scripts start", "build": "react-scripts build", "test": "react-scripts test", "eject": "react-scripts eject" }, "eslintConfig": { "extends": [ "react-app", "react-app/jest" ] }, "browserslist": { "production": [ ">0.2%", "not dead", "not op_mini all" ], "development": [ "last 1 chrome version", "last 1 firefox version", "last 1 safari version" ] } }
Here's App.js
import React from 'react'; import './App.css'; import logo from './logo.svg'; import Header from './components/Header/Header'; import Navbar from './components/Navbar/Navbar'; import Profile from './components/Profile/Profile'; import Dialogs from "./components/Dialogs/Dialogs"; import {BrowserRouter, Route, Routes} from "react-router-dom";
const App = (props) => {
return (
<BrowserRouter>
<div className='app-wrapper'>
<Header/>
<Navbar/>
<div className='app-wrapper-content'>
<Routes>
<Route path='/dialogs' component={Dialogs}/>
<Route path='/profile' component={Profile}/>
</Routes>
</div>
</div>
</BrowserRouter>)
}
export default App;
There's a link in the barn.
import React from "react";
import s from './Navbar.module.css';const Navbar = () => {
return <nav className={s.nav}>
<div className={s.item}>
<a href='/profile'>My Profile</a>
</div>
<div className={s.item}>
<a href='/dialogs'>Messages</a>
</div>
<div className={s.item}>
<a href='#'>News</a>
</div>
<div className={s.item}>
<a href='#'>Friends</a>
</div>
<div className={s.item}>
<a href='#'>Settings</a>
</div></nav>
}
export default Navbar;
Components are available, environments are captured and exported.
This is Dialogs.jsx
import React from "react";
import s from './Dialogs.module.css';const Dialogs = (props) => {
return (
<div>
Dialogs
</div>
)
}export default Dialogs;
This is Profile.jsx
import React from "react";
import s from './Profile.module.css';
import MyPosts from "./MyPosts/MyPosts";const Profile = () => {
return <div>
<div>
<img width='995px' height='400px' src='https://www.wallpapertip.com/wmimgs/5-54174_download-monaco-dawn-wallpaper-free-stock-photo-monaco.jpg' alt=''></img>
</div>
<div>
ava+description
</div>
<MyPosts />
</div>
}
-
Instead of the flow
a
need to use the componentLink
instead of attributehref
Attributionto
<div className={s.item}> <Link to="/profile">My Profile</Link > </div> <div className={s.item}> <Link to="/dialogs">Messages</Link > </div> <div className={s.item}> <Link to="/news">News</Link> </div> <div className={s.item}> <Link to="/friends">Friends</Link > </div> <div className={s.item}> <Link to="/settings">Settings</Link > </div>
There's a good example here. https://v5.reactrouter.com/web/example/basic