1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-09-19 17:52:45 +02:00
unleash.unleash/frontend/src/component/menu/breadcrumb.jsx
Fredrik Strand Oseberg dbed06f300 Feat/material UI (#250)
Co-authored-by: Ivar Conradi Østhus <ivarconr@gmail.com>
Co-authored-by: Christopher Kolstad <chriswk@getunleash.ai>
Co-authored-by: Christopher Kolstad <git@chriswk.no>
2021-03-30 15:14:02 +02:00

63 lines
1.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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 (
<span>
<Link className={styles.headerTitleLink} to={parentRoute.path}>
{parentRoute.title}
</Link>
<span>
<span> </span>
<span className={styles.headerTitleLink}>{currentTitle}</span>
</span>
</span>
);
};
const renderBread = route => {
document.title = `${route.title} - Unleash`;
return (
<span>
<span className={styles.headerTitleLink}>{route.title}</span>
</span>
);
};
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 = () => (
<Switch>
{routes.map(route => (
<Route
key={route.path}
path={route.path}
render={({ match: { params } } = this.props) => renderRoute(params, route)}
/>
))}
</Switch>
);
export default Breadcrumb;