Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React router change url without page reload

When I was using react-router 0.13.3, it was ok: i was changing url and transition without reload was happening.

Now, in react-router 2.0 if I'm changing url manually, my app gets reloaded entirely instead of simple redirect. How do i fix it?

I want to use this:

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

instead this:

<Link to="/routename">link</Link>

In few special cases.

Routes

import {Router, Route, IndexRoute} from "react-router";
import App from './components/App';
import FrontPage from './components/frontPage/FrontPage';
import User from './components/user/User';
module.exports = (
    <Router>
        <Route path="/" component={App}>
            <IndexRoute component={FrontPage}/>
            <Route path="/user/:userid" component={User}/>
        </Route>
    </Router>
);
like image 710
stkvtflw Avatar asked Apr 26 '16 03:04

stkvtflw


People also ask

Does react router change URL?

The react-router-dom package is great for rendering different React components based on the url path. Therefore, React components can lead to others by changing the url path.

How do I refresh a react without reloading?

Method 1: Refresh a Page Using JavaScriptwindow. location. reload(false); This method takes an optional parameter which by default is set to false.

How do I use react router without changing URL?

To use React Router without changing the URL, we can use the MemoryRouter component. to import the MemoryRouter component and then wrap it around App to let us navigate with React Router without changing URLs.


1 Answers

There is no solution. We can either onClick script or Link.

https://github.com/reactjs/react-router/issues/3411

like image 115
stkvtflw Avatar answered Oct 30 '22 20:10

stkvtflw