reactjs - Reload page if click to same path -


:)

i'm trying reload browser (with location.reload();) if user click in <link> the same path, already.

example:

i have menu:

- home - contact -

when user click in 'contact', go '/contact'. in '/contact' , click in 'contact' in menu, page reload.

it's possible this?

what i'm trying:

<link onclick={this.handleclick} to="contact">contact</link>  handleclick(){     var currentroute = 'react-route path';     var linkroute = 'link path';      if (currentroute === linkroute)         location.reload();     } else {         //do default transition     } } 

but don't figure need declare in 'currentroute' , 'linkroute'. :(

you shouldn't reload page. thats bad idea. instead disable link this:

if on home page links this

<a href="/home" data-disabled="true">home</a> <a href="/contact" data-disabled="false">contact</a> <a href="/about" data-disabled="false">about</a> 

then in handleclick() function can this.

handleclick(e){     e.preventdefault();     var disabled = $(e.currenttarget).data('disabled');     if (!disabled){          //do redirect     } } 

basically have data attribute on link specifies if disabled or not (only disabled if on current page) , redirect if on different page

reloading page on exact same page cause lose state , process user has done, doesn't need happen. reduces traffic on server new page load (aka data need load on page load don't have again).


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -