5

I am a little confused on how to do (multiple) optional path parameters from the root. I'm using react-router 3, and redux 4.3.

From what I understand, (/:param1)(/:param2) should work, but I am getting the following error when loading the app:

[react-router] Location "/property/3633" did not match any routes.

index.js:

import React from 'react';

import ReactDOM from 'react-dom';

import { Provider } from 'react-redux';

import { Router, browserHistory, Route } from 'react-router';

import { syncHistoryWithStore } from 'react-router-redux';

import configureStore from './store/configureStore';

import {MyContainer} from "./containers/MyContainer";

const store = configureStore();
const history = syncHistoryWithStore(browserHistory, store);

ReactDOM.render(
    <Provider store={store}>
        <Router history={history}>
            <Route path="/(/:Type)(/:Id)" component={MyContainer}/>
        </Router>
    </Provider>,
    document.getElementById('root'),
);

FYI I have tried:

path="(/:Type)(/:Id)" 
path="(/:Type)/(/:Id)" 
path="/(/:Type)/(/:Id)" 
path="/(/:Type)(/:Id)" 
path="/:Type/:Id" // Only works when params are supplied

And this works:

<Route path="/test(/:Type)(/:Id)" component={MyContainer}/>

But again, this does not:

<Route path="/(/:Type)(/:Id)" component={MyContainer}/>
its30
  • 253
  • 3
  • 17

2 Answers2

1

You need to add some realtive path, rather than directly giving params. <Route path="/get/(:Type)/(:Id)" component={MyContainer}/>

1

Had the same issue today. I managed to resolve it like this:

<Route path="/(:param1)(:/param2) component={SomeComponent}"
Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
dkanas
  • 51
  • 5