react refresh page code example

Example 1: make page refresh on top in react js

onUpdate={window.scrollTo(0, 0)}

componentDidMount() {
  window.scrollTo(0, 0)
}

Example 2: how to refresh the page using react

window.location.reload(false);

Example 3: react router refresh page

location.reload();

Example 4: react router refresh page

`yarn add react-router` or `npm install react-router`

import { useHistory } from 'react-router'
const history = useHistory()
history.go(0)

Example 5: react router browser refresh

// Add the following to .htaccess file in the public folder
// NOTE: This is for Apache servers!

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteRule ^index\.html$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-l
  RewriteRule . /index.html [L]
</IfModule>

Example 6: react router refreshes page

import React from "react";
import { Link } from 'react-router-dom';

export class ToolTip extends React.Component {
  render() {
    return (
      <Link to="/My/Route">Click Here</Link>
    )
  }
};