Link to Reload Current Page

Link to reload current page

I have been using:

<a href=".">link</a>

Have yet to find a case and/or browser where it does not work as intended.

Period means the current path. You can also use .. to refer to the folder above the current path, for instance, if you have this file structure:

page1.html
folder1
page2.html

You can then in page2.html write:

<a href="../page1.html">link to page 1</a>

EDIT:

I'm not sure if the behaviour has changed or if it was always like this, but Chrome (and maybe others) will treat periods as described above as regarding directories, not files. This means that if you are at http://example.com/foo/bar.html you are really in the directory /foo/ and a href value of . in bar.html will refer to /foo/ rather than bar.html

Think of it as navigating the file system in a terminal; you can never cd into a file :)

EDIT 2:

It seems like the behaviour of using href="." is not as predictable anymore, both Firefox and Chrome might have changed how they handle these. I wouldn't rely entirely on my original answer, but rather try both the empty string and the period in different browsers for your specific use and make sure you get the desired behaviour.

How to reload current page?

It will work 100%. The following lines of code are responsible for page reload in my project.

load(val) {
if (val == this.router.url) {
this.spinnerService.show();
this.router.routeReuseStrategy.shouldReuseRoute = function () {
return false;
};
}
}

Just use the following part in your code.

this.router.routeReuseStrategy.shouldReuseRoute = function () {
return false;
};

How to refresh page with a href in Firefox

You can use:

<a href='#' onclick='location.reload(true); return false;'>click me</a>

How do I refresh a page using JavaScript?

Use location.reload().

For example, to reload whenever an element with id="something" is clicked:

$('#something').click(function() {
location.reload();
});

The reload() function takes an optional parameter that can be set to true to force a reload from the server rather than the cache. The parameter defaults to false, so by default the page may reload from the browser's cache.

Refresh page when clicked on link

instead of

javascript:history.go(0);

you may use

javascript:window.location.reload();

React reload page by clicking on same link

My guess is the onclick event is calling the page reload before changing page perhaps?

You could try redirecting using react router dom using something like this maybe?
That way it calls the location change then the refresh?

import { useNavigate } from "react-router-dom";

export default function yourIndexPage({yourprops}) {
let navigate = useNavigate();

function changeLocation(placeToGo){
navigate(placeToGo, { replace: true });
window.location.reload();
}

return(
<ul className='menu'>
<li className="navbar-item">
<Link to="/inventory" onClick={() => changeLocation('/inventory')} className="nav-link">Complete Inventory</Link>
</li>
<li className="navbar-item">
<Link to="/inventory/clusters" onClick={() => changeLocation('/inventory/clusters')} className="nav-link">Inventory based on cluster</Link>
</li>
<li className="navbar-item">
<Link to="/inventory/clusters/servertype" onClick={() => changeLocation('/inventory/clusters/servertype')} className="nav-link">Inventory based on cluster and server type</Link>
</li>
</ul>
)

}

React Link to current URL does not reload page

try these:

user Link:

 <Link to={`${window.location.pathname}`} onClick={()=>{window.location.reload()}}> <img className="img-fluid" src={Logo} alt="Alt_Text /></Link>

Or use a tag:

 <a href={`${window.location.pathname}`}><img className="img-fluid" src={Logo} alt="Alt_Text /></a> 


Related Topics



Leave a reply



Submit