Exorcismus
Exorcismus

Reputation: 2482

How to correctly route between two similar pathnames in reactjs router

I have setup a router with the below configuration

<Router>
    <Switch>
        <Route exact path="/" component={Home} />
        <Template>
            <Switch>
                <Route path="/search?" component={SearchResult} />
                <Route path="/:id" component={PropertyTemplate} />
            </Switch>
         </Template>
    </Switch>
</Router>

I also have a component with the below redirection condition

this.state.searchProperties.length > 0 && <Redirect to={{pathname: `/search?query=${this.state.query}`}} />

Yet it seems to match againse pathname /:id instead of /search?

Upvotes: 0

Views: 24

Answers (1)

varoons
varoons

Reputation: 3887

Remove the '?' int he search route

<Route exact path="/search" component={SearchResult} />

Upvotes: 2

Related Questions