geolessel / react-phoenix

Make rendering React.js components in Phoenix easy
http://reactphoenix.com
MIT License
504 stars 38 forks source link

Router docs #48

Closed jonathanrz closed 4 years ago

jonathanrz commented 4 years ago

Do you have any suggestions how to handle routing inside react components?

I saw some examples with react-router, but you need to duplicate your routes.

geolessel commented 4 years ago

@jonathanrz I don't really, sorry. I don't personally do routing inside React components, so I'm honestly not even sure what roadblocks you are hitting.

jonathanrz commented 4 years ago

@geolessel if you need to render a link inside the react component, how do you handle it?

geolessel commented 4 years ago

@jonathanrz All my routing is handled by Phoenix, so when I need to go to a different page, I'll just stick in a regular a tag. Or, you could wrap it in a custom component (warning: untested code ahead! 😆):

const Link = ({ href, children }) => <a href={href}>{children}</a>

const Component = () => (
  <div>Head back <Link href="/">home</Link>.</div>
)

The downside, of course, is you don't get the awesome Phoenix routes helper for the paths.

geolessel commented 4 years ago

@jonathanrz I'm going to close this for now. If you need anything else, let me know.

jonathanrz commented 4 years ago

@geolessel thanks, I will follow your example