Ad

Can I Use An HTML Form's Action Property To Move Between React Routes?

- 1 answer

I'm trying to build a React app, and getting some trouble with React Router. First of all, my url always has some weird hashstring at its' end. For example: http://localhost:3000/#/?_k=gb3epe

Also, I'm not sure whether the hashtag in the url and the following gibberish are part of the same problem or if they're related to 2 different problems. (I'm currently using React-Router v1.0).

Secondly, I think that the weird URL is preventing me from using the "action" property on forms, and would also like to know if there is a better way to move around React renders then relaying on forms.

Thanks.

Ad

Answer

If we're talking about react-router v1.0, then to remove this hash string you should pass a { queryKey: false } parameter to the createBrowserHistory function.

var createBrowserHistory = require('history/lib/createBrowserHistory');

ReactDOM.render(
  <Router history={ createBrowserHistory({ queryKey: false }) } 
          routes={ ReactRoutes } />, 
  document.getElementById('some-container')
);

To move between routes react-router provides Link component which you can use inside your components.

Ad
source: stackoverflow.com
Ad