score:0
Or you can do it like this. Wrap all sub-components(SignIn or SignUp...) to Wrapper.
and In your Wrapper, add {this.props.child}
I prefer this way because I can manage routes in one place.
App
import React from "react";
import Wrapper from "./wrapper";
import Dashboard from "./Dashboard";
import "./App.css";
import { Route, Switch } from "react-router-dom";
function App() {
return (
<Switch>
<Route exact path="/" component={Wrapper} />
<Route exact path="/dashboard" component={Dashboard} />
// Add these routes to App
<Route exact path='/signin' component={Signin} />
<Route exact path="/register" component={Register} />
</Switch>
);
}
export default App;
Wrapper
import React from "react";
import Navbar from "./Nav";
import Signin from "./Signin";
import Info from "./Info";
import Register from "./Register";
import { Switch, Route } from "react-router-dom";
const Wrapper = () => {
return (
<div className="wrapper">
<Navbar nav={"Home"} navv={"Sign in"} navvv={"Register"} />
<div className="home-body pa5">
<Info />
{...this.props.child} // Replace from <Switch> to this
</div>
</div>
);
};
export default Wrapper;
Login or Signin component
import React from "react";
import { Link,withRouter } from "react-router-dom";
import Wrapper from "./Wrapper";
const Info = () => {
return (
<Wrapper> // Add this
<div className="bg-white-60 br3">
<p className="f1 center pa3 orange sans-serif">
Sick? Skip the clinic queue! <br />
Register now to book an appointment
</p>
<div className="ph3">
<Link
className="f6 link dim ba ph3 pv2 mb2 dib orange bg-near-white mr4"
to="/signin"
>
Sign in
</Link>
<Link
className="f6 link dim ba ph3 pv2 mb2 dib orange bg-near-white mr4"
to="/register"
>
Register
</Link>
</div>
</div>
</Wrapper>
);
};
export default withRouter(Info);
score:0
As Vlad says, first you need to remove the exact
from /
, but also move it down, after the /dashboard
route, so if the URL is exactly /dashboard
will match with the Dashboard
component, otherwise will match with the Wrapper
component. This should work:
function App() {
return (
<Switch>
<Route exact path="/dashboard" component={Dashboard} />
<Route path="/" component={Wrapper} />
</Switch>
);
}
score:1
Remove exact from <Route exact path="/" component={Wrapper} />
and move it to the bottom of Switch
Source: stackoverflow.com
Related Query
- How can I use React Router to change routes from within a component that is also Routed in the Main App.js component?
- How can i remove a Property from a react component on router path change
- How do I manage state on a React component that can have state changed from the parent or from events upon it?
- How can I use react useContext , to show data from context, in the same component
- I can not get the state from react router Link component using useLocation. So how can I pass it?
- How can I use a React component within a Node script?
- How to make a react component that can be controled from outside?
- How can I get a component to render as a parent of protected routes in react router dom?
- How can I use Mocha to unit-test a React component that paints on a <canvas>?
- React - How to make a modal component that I can call from anywhere?
- How can I pass a value from the backend to a React frontend and use that value in the CSS for the frontend?
- How can I pass props from one component to another using Link and router in react
- How do I use a custom DOM node to render to from within a react component
- How can I test react component that fetches the data from firestore?
- how can I change props of component that pass from higher component . reactjs
- React - How do I use a handleInputChange function to change a state value that is within a state value?
- How can I turn the data that is a image came from API to url to use in img tag in react Js
- React Hooks: How can I use a hook to map an array from a dumb component
- React - how to change state within component from another component?
- How can we use a value from component state while exporting in react
- In React components implemented with hooks, how can the latest component state values be read from within setInterval?
- How can I use React Router to nest some routes? And I want to keep a header component
- how to pass props from one component to other in react router that don't have parent child relationship?
- How to store the values from a component that is reused so that I can use the values later?
- How can I transfer an information from child component to parent component React.js with React Router
- How to use react router navigation links from separate component file?
- How can I pass values from a functional component through a React Router Link to another functional component?
- How can I prevent my functional component from re-rendering with React memo or React hooks?
- Making an HTML string from a React component in background, how to use the string by dangerouslySetInnerHTML in another React component
- How can I add a click handler to BODY from within a React component?
More Query from same tag
- what is the best way to setState which contains nested Object
- Custom hook to get data from store, if no then dispatch action and return data
- Monaco editor intellisense font sizing wrong making it unusable
- React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined
- How to filter value based on the nested array value?
- Including local JS and CSS files using Gatsbyjs
- How to get multiple values from child component in Reactjs?
- Media Object doesn't render images
- conditional float of <li>
- React-router - redirect on load?
- Getting wrong clientHeight of a ref inside componentDidMount
- React default props value using null
- Can not upload file to S3 bucket in AWS Amplify
- how to activate a function from another component
- React Horizontal Timeline distance of undefined error
- How to unit test a method of react component?
- this.props react training Question - CodeAcademy
- React wait for function to finish?
- React: Invalid value for prop `savehere` on <div> tag. Either remove it from the element, or pass a string or number value to keep it in the DOM
- React and checking condition after passing function through props
- React Ant Design editable table
- Ant-Design Table not rendering when change state in mobx store
- React js form validation
- Axios get request is in infinite loop
- Approach to react component switching between subcomponents with form
- Reactjs with material UI background color all page
- how to render object array in react?
- Two dialog boxes on one page and enabling checkboxes?
- Redux initial state for variable reducer
- How to get object key from the api call dynamically and change the payload structure format?