route to change a part of component

Solutions on MaxInterview for route to change a part of component by the best coders in the world

showing results for - "route to change a part of component"
Maximilian
29 Mar 2018
1<Route
2  exact
3  path="/"
4  render={props => (
5    <Page {...props} component={Index} title="Index Page" />
6  )}
7/>
8
9<Route
10  path="/about"
11  render={props => (
12    <Page {...props} component={About} title="About Page" />
13  )}
14/>
15
16
17//Page Component
18import React from "react"
19
20/* 
21 * Component which serves the purpose of a "root route component". 
22 */
23class Page extends React.Component {
24  /**
25   * Here, we define a react lifecycle method that gets executed each time 
26   * our component is mounted to the DOM, which is exactly what we want in this case
27   */
28  componentDidMount() {
29    document.title = this.props.title
30  }
31
32  /**
33   * Here, we use a component prop to render 
34   * a component, as specified in route configuration
35   */
36  render() {
37    const PageComponent = this.props.component
38
39    return (
40      <PageComponent />
41    )
42  }
43}
44
45export default Page