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

[Proposal] add sync attribute to Link

Open maxhoffmann opened this issue 11 years ago • 5 comments

In some cases I would like to link to other pages using route names, but still do a full page refresh.

What do you think about adding a sync property?

<Link to="name" />
<Link to="name" sync={true} />

maxhoffmann avatar Dec 11 '14 17:12 maxhoffmann

Just an idea, but you could possibly put a window.location.reload() in the componentWillMount of your destination route. Would that solve your use case?

Edit: This approach would also give you finer-grained control of which components trigger a refresh and which don't, so your <Link>s don't need to know about it. Also, if you have a route that needs a hard refresh for some reason, you can do window.location.reload(true) to force refetching the page from the server.

mjackson avatar Dec 11 '14 18:12 mjackson

Wouldn't that lead to a refresh cycle?

The proposal seems handy to me, although I think sync is a bit misleading. Without having read the text, I initially thought you were asking for a way to force synchronous transitions.

agundermann avatar Dec 11 '14 20:12 agundermann

The technical background is the following: the site I'm working on is mainly rendered on a node.js server that sometimes makes multiple xhr requests to an api to render the requested page. As one important user group are people based in Africa we don’t want them to make these requests from their browser. Instead they make one request to our node server who then does the requests to the api. This is of course much faster as server and api can be in the same country (or even room). Our users in Africa don't have to wait for multiple requests to succeed on their high latency network.

maxhoffmann avatar Dec 11 '14 20:12 maxhoffmann

@taurose The property could be named differently. I’m open for ideas. Do you have something in mind?

maxhoffmann avatar Dec 12 '14 15:12 maxhoffmann

Mixin Navigation:

<a href="{this.makeHref(route, params)}">Will do a full page reload</a>

If I understand the use-case though, I think I'd detect Africa and switch to RefreshLocation in the router.

ryanflorence avatar Feb 01 '15 04:02 ryanflorence