Parameters not handled correctly
egilll opened this issue · comments
Hello, I am opening this issue mainly to allow others who come across this to be aware of the problem, but I am not expecting that it be fixed.
The issue is that the library only supports having a single route with parameters. An example:
const First = (params) => {
console.log(params);
return null;
};
const Second = (params) => {
console.log(params);
return null;
};
const Third = (params) => {
console.log(params);
return null;
};
const items = [
{
path: "/first/:param1",
component: First,
},
{
path: "/second/:param2",
component: Second,
},
{
path: "/third/:param3",
component: Third,
},
];
export const Routes = () => {
return <Switch items={items} history={history} />;
};
If one opens the URL /third/123
, it will output:
{param1: '123', param2: undefined, param3: undefined}
instead of the expected:
{param3: '123'}
I believe this is due to const keys: Key[] = [];
being in the outer lexical scope instead of inside items.reduce
, but I haven't tried it.
I did end up using the library url-pattern instead.
The development of this router was continued at react-declarative. For backward compability, I commited the patch in this repo too