0

I'm using react router to navigate through my application, but I don't want react router to make a call to the server, is that possible?

4
  • Yes react-router does not interface with any server.. nothing in the react stack does it's all client side Commented Mar 29, 2016 at 18:45
  • @azium In my application it does! Commented Mar 29, 2016 at 18:53
  • I don't get what your question is then.. Commented Mar 29, 2016 at 18:53
  • 1
    How are you transitioning routes? If you set location.href directly, you will hit the server, but if you use browserHistory.push(), it will not. That said, if you hit a route directly (i.e. type the address and hit enter). It will hit your server. in that case, you need your server to serve up index.html. See github.com/reactjs/react-router/blob/master/docs/guides/… Commented Mar 29, 2016 at 21:07

1 Answer 1

1

You should use Hash history.

import { Router, Route }  from 'react-router'
import createHashHistory  from 'history/lib/createHashHistory'

<Router history={ createHashHistory({ queryKey: false }) }>
  <Route path="/" component={App} />
</Router>

If you don't want to use the hash history (which appends a # to the url), use the Link Component which will correctly navigate the App based on the history type passed.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.