Fix theme breaking with a slash in url (#1391)

Fixes #1386
This commit is contained in:
Thakur Karthik 2020-10-26 12:30:01 +05:30 committed by GitHub
parent 411c2c24c3
commit 57031fed10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 1 deletions

View File

@ -36,13 +36,15 @@ import { connect } from "react-redux";
import * as Sentry from "@sentry/react";
import AnalyticsUtil from "utils/AnalyticsUtil";
import { trimTrailingSlash } from "utils/helpers";
const SentryRoute = Sentry.withSentryRouting(Route);
const loadingIndicator = <PageLoadingBar />;
function changeAppBackground(currentTheme: any) {
if (
window.location.pathname === "/applications" ||
trimTrailingSlash(window.location.pathname) === "/applications" ||
window.location.pathname.indexOf("/settings/") !== -1
) {
document.body.style.backgroundColor =

View File

@ -117,3 +117,22 @@ export const isMac = () => {
typeof navigator !== "undefined" ? navigator.platform : undefined;
return !platform ? false : /Mac|iPod|iPhone|iPad/.test(platform);
};
/**
* Removes the trailing slashes from the path
* @param path
* @example
* ```js
* let trimmedUrl = trimTrailingSlash('/url/')
* console.log(trimmedUrl) //will output /url
* ```
* @example
* ```js
* let trimmedUrl = trimTrailingSlash('/yet-another-url//')
* console.log(trimmedUrl) // will output /yet-another-url
* ```
*/
export const trimTrailingSlash = (path: string) => {
const trailingUrlRegex = /\/+$/;
return path.replace(trailingUrlRegex, "");
};