Explorar o código

Let `state.href` be detected when refreshing in web mode

Shaun %!s(int64=2) %!d(string=hai) anos
pai
achega
d081766dee
Modificáronse 2 ficheiros con 3 adicións e 2 borrados
  1. 1 1
      package.json
  2. 2 1
      src/index.js

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "@shaun/alpinejs-router",
-  "version": "1.2.11",
+  "version": "1.2.12",
   "description": "Easy to use and flexible router for Alpine.js",
   "type": "module",
   "main": "dist/module.cjs.js",

+ 2 - 1
src/index.js

@@ -7,7 +7,7 @@ export default function (Alpine) {
   const state = Alpine.reactive({
     mode: 'web',
     base: '',
-    href: location.href,
+    href: location.origin,
     path: '',
     query: {},
     params: {},
@@ -68,6 +68,7 @@ export default function (Alpine) {
     state.params = router.match(url)
   })
 
+  Alpine.nextTick(() => state.href = location.href)
   window.addEventListener('popstate', () => state.href = location.href)
 
   function push (path, options = {}) {