I am trying to write a web application's front end using React.js. And I accomplish a Navigate bar component & an alert component when the user inputs the wrong password. When I render these two components, I found they overlapped and I don't know if anything went wrong 😭.
Here are the pictures and code. Thank u so much for your help.
App.js
import './App.css';
import React, { Fragment } from 'react';
import Navbar from './components/layout/Navbar';
import { Landing } from './components/layout/Landing';
import { BrowserRouter as Router, Route, Routes } from 'react-router-dom';
import { Login } from './components/auth/Login';
import Register from './components/auth/Register';
import Alert from './components/layout/Alert';
// Redux
import { Provider } from 'react-redux';
import store from './store';
const App = () => (
<Provider store={store}>
<Router>
<Navbar />
<Alert />
<Routes>
<Route path='/' element={<Landing />} />
<Route path='/register' element={<Register />}></Route>
<Route path='/login' element={<Login />}></Route>
</Routes>
</Router>
</Provider>
);
export default App;
Alert.js
import React from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
const Alert = ({ alerts }) =>
alerts !== null &&
alerts.length > 0 &&
alerts.map((alert) => (
<div key={alert.id} className={`alert alert-${alert.alertType}`}>
{alert.msg}
</div>
));
Alert.propTypes = {
alerts: PropTypes.array.isRequired,
};
const mapStateToProps = (state) => ({
alerts: state.alert,
});
export default connect(mapStateToProps)(Alert);
Navbar.js
import React from 'react';
import { Link } from 'react-router-dom';
const Navbar = () => {
return (
<nav className='navbar bg-dark'>
<h1>
<Link to='/'>
<i className='fas fa-code'></i> DevConnector
</Link>
</h1>
<ul>
<li>
<a href='profiles.html'>Developers</a>
</li>
<li>
<Link to='/register'>Register</Link>
</li>
<li>
<Link to href='/login'>
Login
</Link>
</li>
</ul>
</nav>
);
};
export default Navbar;
please try to replace the nav tag with a div tag in Navbar component
It seems that your nav tag has position fixed. You should to give padding from top (height of your nav) to tag that wraps your pages. If it will not work, can you provide some css related to nav or what css library is used.
PS. Sry for my english.