-
-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Example of breadcrumbs? #36
Comments
I personally like this approach: Route{
path: '/about',
action() {
return <AboutPage />; // or, return { title: 'About Us', component: <AboutPage /> }
}
} Componentimport React from 'react';
import Layout from '../components/Layout';
class AboutPage extends React.Component {
render() {
return (
<Layout breadcrumbs="Home > About">
<h1>About Us</h1>
<p>Bla-bla-bla</p>
</Layout>
);
}
}
export default AboutPage; In the example above, the |
I'm trying to look for automatic breadcrumb with the same example but having nested routes using ex: Thanks. |
@tamerelsayed since v3.0.0 you can do like so: import Router from 'universal-router';
const routes = {
path: '/teams/:teamId',
title: 'Team',
children: [
{
path: '/projects/:projectId',
title: 'Project',
children: [
{
path: '/panel1',
title: 'Panel',
page: 'Panel Page',
},
],
},
],
};
const options = {
resolveRoute(context) {
return context.route.page ? context : null;
}
};
const router = new Router(routes, options);
router.resolve('/teams/1/projects/1/panel1').then(context => {
console.log(context);
const breadcrumbs = [];
let route = context.route;
while (route) {
breadcrumbs.push(route.title);
route = route.parent;
}
document.body.innerHTML =
`<h1>${context.route.title}</h1>` +
`<p>Breadcrumbs: ${breadcrumbs.reverse().join(' → ')}</p>` +
`<p>Content: ${context.route.page}</p>`;
// => <h1>Panel</h1>
// => <p>Breadcrumbs: Team → Project → Panel</p>
// => <p>Content: Panel Page</p>
}); Playground: https://jsfiddle.net/frenzzy/qL66ok9h/ |
@frenzzy how could I get the value of breadcrumbs array to render, thanks 😄 |
@young666 like in the example above? Or if you need this on route level: const route = {
path: '/users',
title: 'Users',
action(context) {
const breadcrumbs = [];
let route = context.route;
while (route) {
breadcrumbs.unshift(route.title);
route = route.parent;
}
console.log(breadcrumbs) // => ['Users']
}
} |
@frenzzy my problem is that resolve return only Promise, I can't get the value inside render() {
const BreadcrumbItems = [];
const router = new UniversalRouter(route, options);
router.resolve(pathname).then(context => {
/* loop to push context.route.title into BreadcrumbItems */
});
// Here's a new BreadcrumbItems get well-prepared to be rendered but it didn't :(
return BreadcrumbItems.map(item => (<span>{item}<span>));
} |
What is |
I'm using react-starter-kit, the pathname variable I only could get it from react context: |
In react-starter-kit you may patch resolveRoute(context, params) {
const breadcrumbs = []
let route = context.route
while (route) {
breadcrumbs.unshift(route.title)
route = route.parent
}
context.breadcrumbs = breadcrumbs // <=
// ...
} |
I'd like to have breadcrumbs for my site. Does anyone have recommendations for implementing them as part of universal-router? Thanks.
--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/36212127-example-of-breadcrumbs?utm_campaign=plugin&utm_content=tracker%2F18115217&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F18115217&utm_medium=issues&utm_source=github).The text was updated successfully, but these errors were encountered: