]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
wip router.push
authorEduardo San Martin Morote <posva13@gmail.com>
Tue, 16 Apr 2019 13:05:17 +0000 (15:05 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Tue, 16 Apr 2019 13:05:17 +0000 (15:05 +0200)
src/history/base.ts
src/router.ts

index 5bcf6e351ae9944b29b586eab714b8496f8ef358..159876c5769a818b11923346ba9a86af6b4a19d0 100644 (file)
@@ -135,7 +135,11 @@ export abstract class BaseHistory {
    * Stringify a URL object
    * @param location
    */
-  stringifyURL(location: HistoryURL): string {
+  stringifyURL(location: {
+    path: string
+    query?: HistoryQuery
+    hash?: string
+  }): string {
     let url = location.path
     let query = '?'
     // TODO: util function?
@@ -155,7 +159,7 @@ export abstract class BaseHistory {
 
     if (query.length > 1) url += query
 
-    return url + location.hash
+    return url + (location.hash || '')
   }
 
   /**
index e2e0ca5179eae168dd0e17becb2b8c3e341bbd7a..afc85349ba96e3318bb381992ea68ba4a4c69ffa 100644 (file)
@@ -5,6 +5,7 @@ import {
   RouteRecord,
   START_LOCATION_NORMALIZED,
   RouteLocationNormalized,
+  RouteQuery,
 } from './types/index'
 
 interface RouterOptions {
@@ -38,13 +39,41 @@ export class Router {
    */
   push(to: RouteLocation) {
     // TODO: resolve URL
-    const url = typeof to === 'string' ? this.history.parseURL(to) : to
+    let url, fullPath: string, query: RouteQuery, hash: string
+    if (typeof to === 'string') {
+      url = this.history.parseURL(to)
+      fullPath = url.fullPath
+      query = url.query
+      hash = url.hash
+    } else if ('path' in to) {
+      fullPath = this.history.stringifyURL(to)
+      query = to.query || {}
+      hash = to.hash || ''
+      url = to
+    } else if ('name' in to) {
+      // we need to resolve first
+      url = to
+    } else {
+      // we need to resolve first
+      url = to
+    }
+    console.log('going to', to)
     const location = this.matcher.resolve(url, this.currentRoute)
+
     console.log(location)
+    // @ts-ignore
+    console.log({ fullPath, query, hash })
+    console.log('---')
     // TODO: call hooks, guards
     // TODO: navigate
     // this.history.push(location.fullPath)
-    // this.currentRoute = location
+    // this.currentRoute = {
+    //   ...url,
+    //   ...location,
+    //   fullPath,
+    //   query,
+    //   hash,
+    // }
   }
 
   getRouteRecord(location: RouteLocation) {}