Answer the question
In order to leave comments, you need to log in
How to use header, nav tags in react-router?
I have this
App.tsx code
import React, { FC, Fragment } from "react";
import Nav from "./Components/Nav/Nav";
const App: FC = () => (
<Fragment>
<Nav />
</Fragment>
);
export default App;
const renderUntitled = ({
match
}: {
match: faceMatch<{ PageList: string }>;
}) => (
<Fragment>
<Logo/>
<FormSearch params={""} />
<ButSearch match={match} />
</Fragment>
);
const Nav: FC = () => {
return (<Fragment>
<nav>
<Link to="/">Amasia</Link>
<Link to="/Mens/Hat/ListPage=15&Page=1">Product</Link>
</nav>
<Switch>
<Route
path="/"
exact
render={({ match }) => (
<Fragment>
<Logo/>
<h1>{"Welcome to Amasia"}</h1>
<FormSearch params={""} />
<ButtLogSing />
<Head match={match} />
</Fragment>
)}
/>
<Route path="/Mens/Hat/:PageList" render={renderUntitled} />
<Route path="*" render={() => <Redirect to="/" />} />
</Switch>
</Fragment>
);
};
<header>
<nav> <Nav/> </nav>
<Logo/>
<FormSearch params={""} />
<ButSearch match={match} />
</header>
<Fragment>
<header>
<nav> <Nav/> </nav>
<Logo/>
<FormSearch params={""} />
<ButSearch match={match} />
</header>
<Head match={match} />
</Fragment>
Answer the question
In order to leave comments, you need to log in
As far as I understand your task, you want to take out the Header and render different pages under it. This can be done, for example, like this:
const Amasia = () => (
<div>Amasia</div>
);
const Product = ({ match }) => (
<div>
Page number: {match.params.page}
</div>
);
const Header = () => (
<header>
<nav>
<Link to="/">Amasia</Link>
<Link to="/Mens/Hat/1">Product</Link>
</nav>
<div>Logo</div>
<div>FormSearch</div>
<div>ButSearch</div>
</header>
);
const App = () => (
<>
<Header />
<main>
<Switch>
<Route exact path="/" component={Amasia} />
<Route exact path="/Mens/Hat/:page" component={Product} />
</Switch>
</main>
</>
);
const rootElement = document.getElementById("root");
ReactDOM.render(
<Router>
<App />
</Router>,
rootElement,
);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question