React-router: Attach router to prerendered html a tags.

Created on 19 May 2016  路  2Comments  路  Source: ReactTraining/react-router

Today, if you display prerendered html (usually via dangerouslySetInnerHTML) that contains <a> tags that refer to a relative path, those links obviously will not get intercepted by react router. This in my opinion is a real bummer for consuming for example a wordpress api.

To be honest I'm not sure if the feature I want to request is even possible, but it would be great if you could either somehow attach to anchor tags containing relative links to route them on the client or intercept every leave and check for the destination and redirect if it's a 'local' link.

Most helpful comment

You could probably achieve that by using document.getElementsByTagName('a') inside the lifecycle methods and then add click listeners that call router.push, similar to how Link does it.

I don't think this is a much requested feature, and it goes against the design/best practices of the router and react, so it probably shouldn't be part of the router itself.

All 2 comments

Those DOM nodes aren't connected to React at all. We have no (reasonable) way of accessing them.

You could probably achieve that by using document.getElementsByTagName('a') inside the lifecycle methods and then add click listeners that call router.push, similar to how Link does it.

I don't think this is a much requested feature, and it goes against the design/best practices of the router and react, so it probably shouldn't be part of the router itself.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ArthurRougier picture ArthurRougier  路  3Comments

jzimmek picture jzimmek  路  3Comments

stnwk picture stnwk  路  3Comments

andrewpillar picture andrewpillar  路  3Comments

nicolashery picture nicolashery  路  3Comments