Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// /lang/stuff/ -> /other-lang/stuff/
(countSlashes(oldPathname) === 3 &&
countSlashes(newPathname) === 3 &&
// /stuff/ === /stuff/
oldPathname.substr(oldPathname.substr(1).indexOf('/') + 1) ===
newPathname.substr(newPathname.substr(1).indexOf('/') + 1))
) {
return true;
}
return false;
}
// Forked to not update scroll on transitions between translations.
// Sadness. I have to override a *plugin* because it already has its own logic,
// and Gatsby just ignores mine, lol. TODO: fork this plugin?
let oldShouldUpdateScroll = require('gatsby-remark-autolink-headers/gatsby-browser')
.shouldUpdateScroll;
if (typeof oldShouldUpdateScroll !== 'function') {
throw new Error('No monkeypatching today :-(');
}
require('gatsby-remark-autolink-headers/gatsby-browser').shouldUpdateScroll = function shouldUpdateScroll({
prevRouterProps,
routerProps,
}) {
const { pathname, hash } = routerProps.location;
if (prevRouterProps) {
const {
location: { pathname: oldPathname },
} = prevRouterProps;
if (shouldPreserveScrollBetween(oldPathname, pathname)) {
return false;
}
newPathname.substr(newPathname.substr(1).indexOf('/') + 1))
) {
return true;
}
return false;
}
// Forked to not update scroll on transitions between translations.
// Sadness. I have to override a *plugin* because it already has its own logic,
// and Gatsby just ignores mine, lol. TODO: fork this plugin?
let oldShouldUpdateScroll = require('gatsby-remark-autolink-headers/gatsby-browser')
.shouldUpdateScroll;
if (typeof oldShouldUpdateScroll !== 'function') {
throw new Error('No monkeypatching today :-(');
}
require('gatsby-remark-autolink-headers/gatsby-browser').shouldUpdateScroll = function shouldUpdateScroll({
prevRouterProps,
routerProps,
}) {
const { pathname, hash } = routerProps.location;
if (prevRouterProps) {
const {
location: { pathname: oldPathname },
} = prevRouterProps;
if (shouldPreserveScrollBetween(oldPathname, pathname)) {
return false;
}
} else {
// Always forget scroll for first load.
return [0, 0];
}
// Call it manually so we have a chance to preserve scroll the line before.