-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #533 from matematikk-mooc/aj/DIT-137
DIT-137: Added support for url navigated course previews on frontpage
- Loading branch information
Showing
4 changed files
with
76 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* Adds, updates, or removes a parameter in the current URL without refreshing the page. | ||
* @param {string} param - The name of the parameter to add, update, or remove. | ||
* @param {string|null} value - The value of the parameter. If set to `null`, the parameter will be removed. | ||
* @returns {string} The modified URL. | ||
*/ | ||
export function shallowUpdateUrlParameter(param, value) { | ||
const urlParams = new URLSearchParams(window.location.search); | ||
if (value === null) { | ||
urlParams.delete(param); | ||
} else { | ||
urlParams.set(param, value); | ||
} | ||
|
||
const baseUrl = window.location.pathname; | ||
const newParams = urlParams.toString(); | ||
const newUrl = baseUrl + (newParams ? '?' + newParams : ''); | ||
|
||
window.history.pushState({ path: newUrl }, '', newUrl); | ||
return newUrl; | ||
} |