score:0
Accepted answer
as far as your task is understood, you want to render header and render different pages under it. this can be done, for example, as follows:
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,
);
score:0
now you can render any component in a separate method.
in your nav.tsx file just define a function as follows.
function amasia({ match }) {
return (
<header>
<nav> <nav/>
<logo/>
<formsearch params={""} />
<butsearch match={match} />
</header>
);
}
function product({ match }) {
return (
<fragment>
<header>
<nav> <nav/>
<logo/>
<formsearch params={""} />
<butsearch match={match} />
</header>
<head match={match} />
</fragment>
);
}
and replace the previous route line
<route exact path="/" component={amasia} />
<route exact path="/mens/hat/:pagelist" component={product} />
Source: stackoverflow.com
Related Query
- How can I use React Router to nest some routes? And I want to keep a header component
- how to use nav link in react with router and bootstrap style
- How to use React Router with Electron?
- How to use React Router with Laravel?
- How to use context api with react router v4?
- How to use React Router on top of Rails router (not using react-rails gem)?
- How can I use history.push('path') in react router 5.1.2 in stateful component?
- How to use Apollo Client + React Router to implement private routes and redirection based on user status?
- How to use react router (createBrowserHistory) on Microsoft IIS to make routing working?
- How to use React Router with Preact
- React router v6 how to use `navigate` redirection in axios interceptor
- How to use meta tags with dynamic value in react js?
- How to use React Router with Material UI Drawer to change content on click?
- How do I use react router with relay?
- How can I use previous location to redirect user in react router v6?
- How to use Browser history in react router with koa
- How to use React Router with match.params?
- How to enable ListItemButton to use React Router v6 Link?
- How can i use param in path as prop react router dom v6
- React Router v6 - How to use @ symbol in route?
- How to use router for switching between components with a key value pair in react
- How to use React Router to replace a Component in render method?
- how to use params in meteor mongo query with react router
- How do I use react router and react scroll on the same button?
- How to use Typescript with React Router and match
- How can I use withRouter in react router v6 for passing props?
- How to use React Router <Link > with an id from antd table column
- How to properly use Router inside Router in React
- How do I use React Router <Link to> from antd table column
- How to use dynamic routing in React router v6
More Query from same tag
- React JS React Query's useMutation: Unable to retrieve the response from the server within the onError callback
- CSS auto hyphens turn into question-mark boxes in Chrome
- Uncaught TypeError: setState is not a function, why isn't it working?
- Returning data from apollo-server based on a filter for a nested field
- How to use combineReducers when having a custom react context hook?
- Resetting redux state on logout
- Getting cannot read properties of undefined error when trying to map through prop generated by getStaticProps function
- How to update Reactjs based PWA to the new version?
- JSX Conditional Rendering for Nested Object Values
- Custom word translator in React
- How can I consistently overwrite JSS styles which have indeterminate suffixes?
- How can I smoothly animate a Material UI LinearProgress over a fixed time period?
- ReactJs only rendering one img element from mapping an array of URLs
- Update nested array in this.setState
- Err: cannot get /
- What does merge do in navigation.navigate (React Native)?
- React chart : prevent chart's canvas scaling with height and width
- Styled-JSX variables not working
- How can I validate a token?
- Code Splitting not working with CRA + React Route v4 + Code Splitting
- React Slick Slider href always points to the same link
- make yield.put happen one after the other in redux-saga
- How to update object property in useState hook?
- typescript types with Promise
- How to resolve getting video data from Django api to reactjs
- React-router redirects to 404 when used with query params
- How do I hide the div that is encapsulating a component from an onClick inside the encapsulated component?
- cant save canvas to image - tainted canvas - react app
- REACT: How to use a variable defined inside .env file?
- Progress circle bar in React JS