react router - how to render Link from content

Sergey Khmelevskoy

How do I render react-router Link component from a paragraph with contents? It might be at random position and I don't find handly sperating content param to beforeText, link and afterText object

Let's say I'm building a blog where the blog-post section is passing content with some url's to the text rendering component and it be Link to internal app route (or might be not, just plain text)

  class ParentComponent extends Component{
    render(){
      <Content content='Lorem ... <Link to="/page">Some link</Link> lorem ipsum ...'
    }
  }


  class Content extends Component {
     const { content } = this.props
     render(){
       <div className="text-section">
         {content}
       </div>
     }
   }
Facundo Larrosa

You should use this.props.children for passing nested components so that they can be rendered straight forward. Your code should then look like this:

 class ParentComponents extends Component{
     render(){
         <Content>
          <p>Lorem ...<Link to="/page">Some link</Link>lorem ipsum</p>
         </Content> 
     }
 }


class Content extends Component {
    render(){
        <div className="text-section">
            {this.props.children}
        </div>
    }

}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

React JS - React Router - Render content separately

From Dev

How to make React-Router to render an interactive output from the server?

From Dev

React with react-router: render component by replacing content in an element

From Dev

React Router changes Link but doesnt render proper component

From Dev

How to render a nested component with react-router

From Dev

React-Router Link, how to trigger a click event on a Link from another component

From Dev

React router: Create 'Link to' paths from objects

From Java

React-router: How to manually invoke Link?

From Java

How to use React Router Link on a landing page?

From Dev

How to refer state in link on react-router

From Dev

How to render HTML content coming from Model

From Dev

Testing React Router with Link

From Dev

How to dynamically render <router-link> or <a> in Vue depending on whether the link is exrternal or internal?

From Dev

How to add a route that will render a component using react-router-dom?

From Dev

How to render common header and footer in react-native-router-flux?

From Dev

Render Content Dynamically from an array map function in React Native

From Dev

How to get the link from content in php

From Dev

Render multiple components in React Router

From Dev

React-router : render is not a function

From Dev

React router history not render correctly

From Dev

React router getIndexRoute does not render

From Dev

React router 3 wont render

From Dev

How to render component from a function outside the render method in React?

From Dev

How to render random objects from an array in React?

From Dev

How to render a react component from a string name

From Dev

How to render a modal with map() from arraylist in react

From Dev

React render link containing a variable

From Dev

react-router: How to disable a <Link>, if its active?

From Dev

How to create a dynamic Link to attribute in React-Router 2.5

Related Related

  1. 1

    React JS - React Router - Render content separately

  2. 2

    How to make React-Router to render an interactive output from the server?

  3. 3

    React with react-router: render component by replacing content in an element

  4. 4

    React Router changes Link but doesnt render proper component

  5. 5

    How to render a nested component with react-router

  6. 6

    React-Router Link, how to trigger a click event on a Link from another component

  7. 7

    React router: Create 'Link to' paths from objects

  8. 8

    React-router: How to manually invoke Link?

  9. 9

    How to use React Router Link on a landing page?

  10. 10

    How to refer state in link on react-router

  11. 11

    How to render HTML content coming from Model

  12. 12

    Testing React Router with Link

  13. 13

    How to dynamically render <router-link> or <a> in Vue depending on whether the link is exrternal or internal?

  14. 14

    How to add a route that will render a component using react-router-dom?

  15. 15

    How to render common header and footer in react-native-router-flux?

  16. 16

    Render Content Dynamically from an array map function in React Native

  17. 17

    How to get the link from content in php

  18. 18

    Render multiple components in React Router

  19. 19

    React-router : render is not a function

  20. 20

    React router history not render correctly

  21. 21

    React router getIndexRoute does not render

  22. 22

    React router 3 wont render

  23. 23

    How to render component from a function outside the render method in React?

  24. 24

    How to render random objects from an array in React?

  25. 25

    How to render a react component from a string name

  26. 26

    How to render a modal with map() from arraylist in react

  27. 27

    React render link containing a variable

  28. 28

    react-router: How to disable a <Link>, if its active?

  29. 29

    How to create a dynamic Link to attribute in React-Router 2.5

HotTag

Archive