Fix blank url pushstate (#7)
* Update dependencies * Fix Root path string Add a method toUrlString that provides a default path as "/" for Root
This commit is contained in:
parent
253f8ebbf3
commit
211941d1cb
12
build.sbt
12
build.sbt
@ -8,7 +8,7 @@ val compilerPlugins = Seq(
|
|||||||
)
|
)
|
||||||
|
|
||||||
val versions = new {
|
val versions = new {
|
||||||
val scalatest = "3.0.5"
|
val scalatest = "3.1.0-SNAP11"
|
||||||
val outwatch = "676f94a"
|
val outwatch = "676f94a"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,11 +73,8 @@ lazy val router = project
|
|||||||
.enablePlugins(ScalaJSBundlerPlugin)
|
.enablePlugins(ScalaJSBundlerPlugin)
|
||||||
.settings(commonSettings)
|
.settings(commonSettings)
|
||||||
.settings(
|
.settings(
|
||||||
scalaJSModuleKind := ModuleKind.CommonJSModule,
|
|
||||||
scalacOptions += "-P:scalajs:sjsDefinedByDefault",
|
|
||||||
useYarn := true, // makes scalajs-bundler use yarn instead of npm
|
useYarn := true, // makes scalajs-bundler use yarn instead of npm
|
||||||
jsEnv in Test := new org.scalajs.jsenv.jsdomnodejs.JSDOMNodeJSEnv,
|
requireJsDomEnv in Test := true,
|
||||||
scalaJSModuleKind := ModuleKind.CommonJSModule, // configure Scala.js to emit a JavaScript module instead of a top-level script
|
|
||||||
version in webpack := "4.16.1",
|
version in webpack := "4.16.1",
|
||||||
version in startWebpackDevServer := "3.1.4",
|
version in startWebpackDevServer := "3.1.4",
|
||||||
webpackDevServerExtraArgs := Seq("--progress", "--color"),
|
webpackDevServerExtraArgs := Seq("--progress", "--color"),
|
||||||
@ -102,11 +99,6 @@ lazy val router = project
|
|||||||
)
|
)
|
||||||
.settings(publishSettings)
|
.settings(publishSettings)
|
||||||
|
|
||||||
lazy val exampleApp = (project in file("router-example"))
|
|
||||||
.settings(name := "outwatch-example")
|
|
||||||
.settings(commonSettings)
|
|
||||||
.dependsOn(router)
|
|
||||||
|
|
||||||
lazy val root = project
|
lazy val root = project
|
||||||
.in(file("."))
|
.in(file("."))
|
||||||
.settings(name := "outwatch-router-root")
|
.settings(name := "outwatch-router-root")
|
||||||
|
@ -15,6 +15,8 @@ trait Path {
|
|||||||
def parent: Path
|
def parent: Path
|
||||||
def lastOption: Option[String]
|
def lastOption: Option[String]
|
||||||
def startsWith(other: Path): Boolean
|
def startsWith(other: Path): Boolean
|
||||||
|
def pathString: String
|
||||||
|
def toUrlString: String = if (pathString.isEmpty) "/" else pathString
|
||||||
}
|
}
|
||||||
|
|
||||||
object Path {
|
object Path {
|
||||||
@ -80,8 +82,12 @@ final case class /(parent: Path, child: String) extends Path {
|
|||||||
|
|
||||||
def lastOption: Some[String] = Some(child)
|
def lastOption: Some[String] = Some(child)
|
||||||
|
|
||||||
lazy val asString: String = s"$parent/${UrlCodingUtils.pathEncode(child)}"
|
lazy val asString: String = s"${parent.pathString}/${UrlCodingUtils.pathEncode(child)}"
|
||||||
|
|
||||||
override def toString: String = asString
|
override def toString: String = asString
|
||||||
|
|
||||||
|
def pathString: String = asString
|
||||||
|
|
||||||
def startsWith(other: Path): Boolean = {
|
def startsWith(other: Path): Boolean = {
|
||||||
val components = other.toList
|
val components = other.toList
|
||||||
toList.take(components.length) === components
|
toList.take(components.length) === components
|
||||||
@ -115,7 +121,8 @@ case object Root extends Path {
|
|||||||
def toList: List[String] = Nil
|
def toList: List[String] = Nil
|
||||||
def parent: Path = this
|
def parent: Path = this
|
||||||
def lastOption: None.type = None
|
def lastOption: None.type = None
|
||||||
override def toString = ""
|
override def toString = "Root"
|
||||||
|
def pathString: String = ""
|
||||||
def startsWith(other: Path): Boolean = other == Root
|
def startsWith(other: Path): Boolean = other == Root
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,15 @@
|
|||||||
|
package outwatch
|
||||||
|
package router
|
||||||
|
|
||||||
|
import org.scalatest._
|
||||||
|
import org.scalatest.flatspec.AnyFlatSpec
|
||||||
|
|
||||||
|
class PathTestSpec extends AnyFlatSpec with Matchers {
|
||||||
|
class PathTest(url: String, path: Path){
|
||||||
|
path.toUrlString should equal (url)
|
||||||
|
}
|
||||||
|
|
||||||
|
"Root url" should "be /" in new PathTest("/", Root)
|
||||||
|
"A 1 part path" should "be correct" in new PathTest("/search", Root / "search")
|
||||||
|
}
|
||||||
|
|
@ -1 +1 @@
|
|||||||
sbt.version=1.2.3
|
sbt.version=1.3.0-RC2
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
addSbtPlugin("ch.epfl.scala" % "sbt-scalajs-bundler" % "0.13.1")
|
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.28")
|
||||||
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.26")
|
addSbtPlugin("ch.epfl.scala" % "sbt-scalajs-bundler" % "0.15.0-0.6")
|
||||||
addSbtPlugin("org.scalameta" % "sbt-mdoc" % "1.2.8" )
|
addSbtPlugin("org.scalameta" % "sbt-mdoc" % "1.2.8" )
|
||||||
addSbtPlugin("com.47deg" % "sbt-microsites" % "0.8.0")
|
addSbtPlugin("com.47deg" % "sbt-microsites" % "0.8.0")
|
||||||
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "2.3")
|
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "2.3")
|
||||||
|
Loading…
Reference in New Issue
Block a user