Skip to content

Commit

Permalink
Merge pull request #2251 from Inist-CNRS/2213-cannot-read-properties-…
Browse files Browse the repository at this point in the history
…of-undefined-reading-startswith

avoid crash if Breadcrumb as no url
  • Loading branch information
touv authored Dec 6, 2024
2 parents b6d8ec3 + 903519c commit 99d23e5
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/app/js/public/breadcrumb/BreadcrumbItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,29 @@ const styles = stylesToClassname(

const BreadcrumbItem = ({ value, p: polyglot }) => {
const label = value.label[polyglot.currentLocale];
const to = String(value.url).trim() || './';
let props = {
to: value.url,
to,
};

if (value.url.startsWith('https://')) {
if (to.startsWith('https://')) {
props = {
href: value.url,
href: to,
};
} else if (value.isExternal === true) {
props = {
href: value.url,
href: to,
target: '_blank',
rel: 'noopener noreferrer',
};
} else if (
// if value.url contain .html, it's a static page. Use href instead of to with react-router default route
value.url.indexOf('.html') !== -1 &&
// if props.to contain .html, it's a static page. Use href instead of to with react-router default route
to.indexOf('.html') !== -1 &&
typeof sessionStorage !== 'undefined'
) {
const tenant = sessionStorage?.getItem('lodex-tenant');
props = {
href: `/instance/${tenant}/${value.url}`,
href: `/instance/${tenant}/${to}`,
rel: 'noopener noreferrer',
};
}
Expand Down

0 comments on commit 99d23e5

Please sign in to comment.