Skip to content

Commit

Permalink
fix: fall back to seeing the current pattern's query string to all
Browse files Browse the repository at this point in the history
…or the defaultPattern value if undefined when the iframe page initially loads
  • Loading branch information
sghoweri committed Sep 5, 2019
1 parent d645ea1 commit a368459
Showing 1 changed file with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,15 @@ class IFrame extends BaseComponent {

// update the currently active nav + add / update the page's query string
handlePageLoad(e) {
var queryString = window.location.search;
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
let patternParam = urlParams.get('p');
const patternParam = urlParams.get('p');

if (e.detail.pattern) {
document.title = 'Pattern Lab - ' + e.detail.pattern;
const currentPattern =
e.detail.pattern || window.config.defaultPattern || 'all';

if (currentPattern) {
document.title = 'Pattern Lab - ' + currentPattern;

const addressReplacement =
window.location.protocol === 'file:'
Expand All @@ -68,21 +71,21 @@ class IFrame extends BaseComponent {
window.location.host +
window.location.pathname.replace('index.html', '') +
'?p=' +
e.detail.pattern;
currentPattern;

// first time hitting a PL page -- no query string on the current page
if (patternParam === null) {
window.history.replaceState(
{
currentPattern: e.detail.pattern,
currentPattern: currentPattern,
},
null,
addressReplacement
);
} else {
window.history.replaceState(
{
currentPattern: e.detail.pattern,
currentPattern: currentPattern,
},
null,
addressReplacement
Expand Down

0 comments on commit a368459

Please sign in to comment.