fixes bug in client side routing

This commit is contained in:
James
2020-01-19 22:10:38 -05:00
parent 349a3c5c87
commit eaaf1863df
2 changed files with 63 additions and 59 deletions

View File

@@ -1,4 +1,4 @@
import React, { useState, useEffect } from 'react';
import React, { useState, useEffect, Fragment } from 'react';
import {
Route, Switch, withRouter, Redirect,
} from 'react-router-dom';
@@ -70,52 +70,59 @@ const Routes = () => {
{config.collections.map((collection) => {
const components = collection.components ? collection.components : {};
return (
<Switch key={collection.slug}>
<Route
path={`${match.url}/collections/${collection.slug}/create`}
exact
render={(routeProps) => {
return (
<Edit
{...routeProps}
collection={collection}
/>
);
}}
/>
<Route
path={`${match.url}/collections/${collection.slug}/:id`}
exact
render={(routeProps) => {
return (
<Edit
{...routeProps}
collection={collection}
/>
);
}}
/>
<Route
path={`${match.url}/collections/${collection.slug}`}
exact
render={(routeProps) => {
const ListComponent = components.List ? components.List : List;
return (
<ListComponent
{...routeProps}
collection={collection}
/>
);
}}
/>
<Route>
<NotFound />
</Route>
</Switch>
<Route
key={collection.slug}
path={`${match.url}/collections/${collection.slug}`}
exact
render={(routeProps) => {
const ListComponent = components.List ? components.List : List;
return (
<ListComponent
{...routeProps}
collection={collection}
/>
);
}}
/>
);
})}
{config.collections.map((collection) => {
return (
<Route
key={collection.slug}
path={`${match.url}/collections/${collection.slug}/:id`}
exact
render={(routeProps) => {
return (
<Edit
{...routeProps}
collection={collection}
/>
);
}}
/>
);
})}
{config.collections.map((collection) => {
return (
<Route
key={collection.slug}
path={`${match.url}/collections/${collection.slug}/create`}
exact
render={(routeProps) => {
return (
<Edit
{...routeProps}
collection={collection}
/>
);
}}
/>
);
})}
<Route path={`${match.url}*`}>
<NotFound />
</Route>
</Switch>
);
}

View File

@@ -1,26 +1,23 @@
import React, { useEffect } from 'react';
import React from 'react';
import PropTypes from 'prop-types';
import { useStepNav } from '../../../modules/StepNav';
import DefaultTemplate from '../../../layout/DefaultTemplate';
import './index.scss';
const ListView = (props) => {
const { setStepNav } = useStepNav();
const { collection } = props;
useEffect(() => {
setStepNav([
{
label: collection.labels.plural,
},
]);
}, []);
return (
<article className="collection-list">
<DefaultTemplate
className="collection-list"
stepNav={[
{
label: collection.labels.plural,
},
]}
>
<h1>{collection.labels.plural}</h1>
</article>
</DefaultTemplate>
);
};