Comments (7)
When i go to route /scenario/edit/:id I need breadscrumb as Home/scenario/editwithid currently getting edit scenario twice.
By default, this HOC will attempt to create breadcrumbs for you. What you probably want to do is disable the default for this specific path.
Also if my route is /admin/apps/list I just want bread crumb as home/admin/list. How do i acheive this ?
Same kinda solution as above, you should be able to disable the default breadcrumb for /admin/apps
...Though if you find yourself disabling a lot of specific routes, the best solution might just be to disable all defaults! That way, you can explicitly define which and what breadcrumbs you want for all routes.
from react-router-breadcrumbs-hoc.
@amitkumarsingh here's a codesandbox of what you're describing (I think) https://codesandbox.io/s/k9p8k65pov
Note, in components/Breadcrumbs
I'm using excludePaths: ["/scenario"]
to avoid generating a default breadcrumb for this specific path section. Then, only the breadcrumbs for edit, create, and details will render.
from react-router-breadcrumbs-hoc.
Does not solve the purpose though.
Say i have route as
{ path: '/scenario/edit/:id?', component: ScenarioModelComposer, exact: true, breadcrumb: 'Edit Scenario', },
{ path: '/scenario/details/:id?', component: ScenarioModelDetails, exact: true, breadcrumb: 'Scenario Details', },
Then i want my breadcrumb as home > scenario > edit scenario
but currently am getting home > scenario > edit scenario > edit scenario
How to solve this ?
from react-router-breadcrumbs-hoc.
@amitkumarsingh Oops, didn't mean to close the issue there ๐ฌ. I think I just realized what might be going on... you're seeing the double generated breadcrumbs only when the id
param is present right?
The main issue here is that this HOC iterates through each section of the path looking for a breadcrumb match, so both /scenario/edit
and scenario/edit/id
match to the same breadcrumb. There are a couple ways to go about fixing this. Generally I'd recommend the latter fix, but either should fix your use case.
I also don't see a single example of a ?
inside of a route in the react-router docs... are you sure you need those?
Quick solve
Use the excludePaths
option to exclude the paths-section not containing the id
param:
withBreadcrumbs(routes, {
excludePaths: ["/scenario/edit", "/scenario/details"]
})(Breadcrumbs)
https://codesandbox.io/s/k9ozozvpy7
Probably better solve
Disable default generated breadcrumbs entirely and only use the ones provided in your route config. This also involves adjusting your route config from scenario/edit/:id?
to scenario/edit/:id
.
https://codesandbox.io/s/o9z4vz5l26
from react-router-breadcrumbs-hoc.
My App.js code is this.
<Provider store={store}>
<BrowserRouter>
<Bootstrap>
<Switch>
{routes.map((item, index) => {
return (
<SensemakerRoute
key={index}
path={item.path}
exact={item.exact}
component={item.component}
store={store}
routes={item.routes}
/>
);
})}
</Switch>
</Bootstrap>
</BrowserRouter>
</Provider>
And my sensemaker code is this. Where am mounting the breadcrumb HOC and passing the breadcrumb as props ?
const SensemakerRoute = ({ component: Component, store, ...rest }: any) => {
return (
<Route
{...rest}
render={(props) => {
return isAuthenticated(store, props) ? (
<Component {...props} breadcrumbs={rest.breadcrumbs} />
) : (
<Redirect to="/home" />
);
}}
/>
);
};
export default withBreadcrumbs(routes ,{
disableDefaults: true,
})(SensemakerRoute);
But in your case your are mounting HOC on breadcrumb component itself ? Not working for me.
from react-router-breadcrumbs-hoc.
It shouldn't matter where it is mounted as long as it is somewhere within a react-router Router component. Either codesandbox link above should fix the issue for you. Make sure to check components/Breadcrumbs
and modules/routeConfig
in each. The excludePaths option should be easier to validate first.
from react-router-breadcrumbs-hoc.
It worked. Thanks ๐
from react-router-breadcrumbs-hoc.
Related Issues (20)
- Translated breadcrumbs (delaying routes init) HOT 1
- dassad
- Unnecessary peer dependency on react-router-dom HOT 4
- "//" produces double matches HOT 1
- Unable to pass additional props. HOT 3
- define breadcrumbโs description HOT 2
- Disabling default generated breadcrumbs by passing breadcrumb: null raises an error HOT 2
- Property 'match' does not exist on type 'ReactNode' HOT 1
- What to use instead of InjectedProps HOT 3
- Replacing react-router with react-router-dom HOT 2
- Fixed
- Suppress autmatically added Home Breadcrumb HOT 2
- Issue with excludePaths not being consistent with breadcrumbs: null HOT 6
- Question about type definition HOT 3
- typescript definition mistake HOT 1
- How do I add in between crumbs ? HOT 2
- Question: Is there a way to not export the current page in breadcrumbs HOT 2
- Question: breadcrumbs propTypes HOT 1
- How to remove "-" from titles HOT 3
- react-router v6 HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-router-breadcrumbs-hoc.