react-router-component icon indicating copy to clipboard operation
react-router-component copied to clipboard

When no routes are defined, <Link> still uses routing

Open atombender opened this issue 11 years ago • 4 comments
trafficstars

We have an application where we use <Link> extensively. We embed fragments of this app in external custom sites, using scripts or iframes. In that case, the fragment will use <Link>, but there will be no router, since the whole app isn't running; we don't control the page itself, so we can't install any routing, use pushState() etc.

Unfortunately, it looks like <Link> will always involve the routing machinery, even if there is no connection between the environment and a router. I could install a custom environment that simply set window.location, but that seems like an awkward solution for something that should be simple: When there is no routing going on, <Link> should simply behave like <a>.

atombender avatar Aug 11 '14 17:08 atombender

In those other projects, instead of using Link from this package, can you just alias Link to React.DOM.a?

sunetos avatar Aug 30 '14 21:08 sunetos

Not sure what you mean by "other projects". There is just one app. Currently we use our own custom Link component that detects whether routing is currently available, and uses <a> otherwise. But this should be unnecessary.

atombender avatar Aug 31 '14 02:08 atombender

"Other projects" => "external custom sites". Sounds like you're already covered with your Link component. Could you take the logic from your custom Link, paste it into the main Link, and make a Pull Request?

sunetos avatar Aug 31 '14 13:08 sunetos

No, my custom link component depends on a global boolean in my app, set at start time — it has no idea whether routing has actually been set up inside react-router-component.

atombender avatar Aug 31 '14 18:08 atombender