]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
test: refactor to not use state
authorEduardo San Martin Morote <posva13@gmail.com>
Fri, 23 Oct 2020 07:45:48 +0000 (09:45 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Fri, 23 Oct 2020 07:45:56 +0000 (09:45 +0200)
e2e/modal/index.ts

index d9146882e432dfeb8febee0b896723f413378269..f2e11fa9744575140fc16ba6647b236315bcbd5c 100644 (file)
@@ -16,20 +16,20 @@ const users = readonly([
   { name: 'James' },
 ])
 
+const historyState = ref(history.state)
+
 async function showUserModal(id: number) {
   // add backgroundView state to the location so we can render a different view from the one
   const backgroundView = router.currentRoute.value.fullPath
 
   await router.push({
     name: 'user',
-    params: { id: '' + id },
-    state: { backgroundView },
+    params: { id },
+    // state: { backgroundView },
   })
-  const newState = {
-    ...window.history.state,
-    backgroundView,
-  }
-  window.history.replaceState(newState, '')
+
+  history.replaceState({ ...history.state, backgroundView }, '')
+  historyState.value = history.state
 }
 
 function closeUserModal() {
@@ -65,7 +65,7 @@ const Home = defineComponent({
   setup() {
     const modal = ref<HTMLDialogElement | HTMLElement>()
     const route = useRoute()
-    const historyState = computed(() => route.fullPath && window.history.state)
+    // const historyState = computed(() => route.fullPath && window.history.state)
 
     const userId = computed(() => route.params.id)
 
@@ -138,6 +138,10 @@ const router = createRouter({
   ],
 })
 
+router.afterEach(() => {
+  historyState.value = history.state
+})
+
 router.beforeEach((to, from, next) => {
   console.log('---')
   console.log('going from', from.fullPath, 'to', to.fullPath)
@@ -149,7 +153,7 @@ router.beforeEach((to, from, next) => {
 const app = createApp({
   setup() {
     const route = useRoute()
-    const historyState = computed(() => route.fullPath && window.history.state)
+    // const historyState = computed(() => route.fullPath && window.history.state)
     const routeWithModal = computed(() => {
       if (historyState.value.backgroundView) {
         return router.resolve(