S
S
Shakir Darion2019-08-07 17:49:31
React
Shakir Darion, 2019-08-07 17:49:31

Map url by React-Router?

I have a search form with a url like localhost:3000/search? Keyword=xxx&subject=AAA&filter2=BBB etc. How do I create a react route for the URL so that the user can bookmark the search? My index.js code is below:

import { Route, Link, BrowserRouter as Router } from 'react-router-dom';
const routing = (
<Router>
  <div>
    <Route path="/" component={App} />

  </div>
</Router>
)
ReactDOM.render(routing, document.getElementById('root'))

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2019-08-07
@shakiriker

<Switch>
  <Route exact path="/" component={App} />
  <Route path="/search" component={Results} />
</Switch>

const Results = ({ location }) => {
  const { search } = location;
  // do something with search
  return ( ... );
};

search will have a string value of the form:
It must be parsed in any way convenient for you.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question