import React from 'react';
import { Link, Route, Switch } from 'react-router-dom';
import { routes, getRoute } from './routes';
import styles from '../styles.module.scss';
const renderDoubleBread = (currentTitle, parentRoute) => {
document.title = `${currentTitle} - ${parentRoute.title} - Unleash`;
return (
{parentRoute.title}
›
{currentTitle}
);
};
const renderBread = route => {
document.title = `${route.title} - Unleash`;
return (
{route.title}
);
};
const renderRoute = (params, route) => {
if (!route) {
return null;
}
const title = route.title.startsWith(':')
? params[route.title.substring(1)]
: route.title;
return route.parent
? renderDoubleBread(title, getRoute(route.parent))
: renderBread(route);
};
/*
Render the breadcrumb.
We only support two levels.
Examples:
- Features
- Features > Create
- Features > SomeToggle
*/
const Breadcrumb = () => (
{routes.map(route => (
renderRoute(params, route)
}
/>
))}
);
export default Breadcrumb;