diff --git a/package.json b/package.json index 7214d828c..35378c664 100644 --- a/package.json +++ b/package.json @@ -167,6 +167,7 @@ "i18next": "^19.9.2", "i18next-browser-languagedetector": "^5.0.1", "isomorphic-fetch": "^2.2.1", + "join-url": "^2.0.0", "jsdom": "^15.1.1", "jsdom-global": "^3.0.2", "koa": "^2.13.4", diff --git a/src/app/profiles/App/Pages/index.tsx b/src/app/profiles/App/Pages/index.tsx index 29e5f7fde..01dafd4bf 100644 --- a/src/app/profiles/App/Pages/index.tsx +++ b/src/app/profiles/App/Pages/index.tsx @@ -7,11 +7,12 @@ import Profiles from './Profiles'; import Error from './Error'; import Subscriptions from './Subscriptions'; import { getFacet } from '../../../../libs/facets/getFacet'; +import { getPathPrefix } from '../../../../libs/facets/getPathPrefix'; const Pages = () => { useChangeLanguage(); const { t, i18n } = useTranslation(); - const prefix = getFacet() === 'lmel' ? '' : `/${i18n.language}`; + const prefix = getPathPrefix(i18n); return ( <> diff --git a/src/app/profiles/App/pathToContributor.ts b/src/app/profiles/App/pathToContributor.ts index 6d74ef18f..58699279b 100644 --- a/src/app/profiles/App/pathToContributor.ts +++ b/src/app/profiles/App/pathToContributor.ts @@ -1,11 +1,16 @@ import slugify from 'slugify'; import i18n from 'i18next'; +import join from 'join-url'; import { Contributor } from 'libs/domain/contributor'; +import { getPathPrefix } from '../../../libs/facets/getPathPrefix'; const pathToContributor = (contributor: Contributor) => { - return `${i18n.t('path.profiles.contributors')}/${contributor.id}/${slugify( - contributor.name - )}`; + return join.pathname( + getPathPrefix(i18n), + i18n.t('path.profiles.contributors'), + contributor.id, + slugify(contributor.name) + ); }; export default pathToContributor; diff --git a/src/index.d.ts b/src/index.d.ts index c6478a19a..8c4bcd06e 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -6,3 +6,5 @@ declare module '*.mp4' { } // eslint-disable-next-line import/order declare module 'react-adobe-animate'; + +declare module 'join-url'; diff --git a/src/libs/facets/getPathPrefix.ts b/src/libs/facets/getPathPrefix.ts new file mode 100644 index 000000000..4c4314d55 --- /dev/null +++ b/src/libs/facets/getPathPrefix.ts @@ -0,0 +1,5 @@ +import { i18n } from 'i18next'; +import { getFacet } from './getFacet'; + +export const getPathPrefix = (i18n: i18n): string => + getFacet() === 'lmel' ? '' : `/${i18n.language}`; diff --git a/yarn.lock b/yarn.lock index 7574896df..8b19143fd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10923,6 +10923,11 @@ join-component@^1.1.0: resolved "https://registry.yarnpkg.com/join-component/-/join-component-1.1.0.tgz#b8417b750661a392bee2c2537c68b2a9d4977cd5" integrity sha1-uEF7dQZho5K+4sJTfGiyqdSXfNU= +join-url@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/join-url/-/join-url-2.0.0.tgz#a80b63a58eba5b44abaf793c17c3b5817ef69e1b" + integrity sha1-qAtjpY66W0Srr3k8F8O1gX72nhs= + js-string-escape@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/js-string-escape/-/js-string-escape-1.0.1.tgz#e2625badbc0d67c7533e9edc1068c587ae4137ef"