Skip to content

Commit 9ba3560

Browse files
committed
Add removeQuery to Router DSL
1 parent 6b77adf commit 9ba3560

File tree

2 files changed

+11
-0
lines changed
  • doc/changelog
  • extra/src/main/scala/japgolly/scalajs/react/extra/router

2 files changed

+11
-0
lines changed

doc/changelog/1.1.0.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
* [Router] Add a new `Redirect.Method` called `Redirect.Force` which bypasses the History API and
44
redirects by setting `window.location.href` directly.
55

6+
* [Router] Add a new rewrite rule `removeQuery` which removes the query portion of a URL.
7+
(e.g. `a/b?c=1` to `a/b`)
8+
69
* Fix React warnings with SVG VDOM.
710

811
* Fix VDOM attributes not accepting types: `Byte`, `Short`, `Float`, `Double`, `Long`

extra/src/main/scala/japgolly/scalajs/react/extra/router/Dsl.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,14 @@ final class RouterConfigDsl[Page] {
623623
// -------------------------------------------------------------------------------------------------------------------
624624
// Utilities
625625

626+
/**
627+
* Removes the query portion of the URL.
628+
*
629+
* e.g. `a/b?c=1` to `a/b`
630+
*/
631+
def removeQuery: Rule =
632+
rewritePathR("^(.*?)\\?.*$".r, m => redirectToPath(m group 1)(Redirect.Replace))
633+
626634
/**
627635
* A rule that uses a replace-state redirect to remove trailing slashes from route URLs.
628636
*/

0 commit comments

Comments
 (0)