]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
wip
authorEduardo San Martin Morote <posva13@gmail.com>
Fri, 12 Apr 2019 14:52:21 +0000 (16:52 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Fri, 12 Apr 2019 14:52:21 +0000 (16:52 +0200)
src/history/abstract.ts
src/history/base.ts
src/history/html5.ts

index 93e8460a8c0c2b8b4b81963fc24980d0183ad2e4..9e162018a94d504cf62bf38dfee19ce73386ad2e 100644 (file)
@@ -10,6 +10,7 @@ export class AbstractHistory extends BaseHistory {
 
   constructor() {
     super()
+    cs.info('created')
   }
 
   // TODO: is this necessary
index 767ffffca4bb7307897722158fbac914d38825ec..eb0a4e3ac3b394da66760c8c3c93898e2365a1a4 100644 (file)
@@ -39,6 +39,8 @@ export interface NavigationCallback {
 
 export type RemoveListener = () => void
 
+const PERCENT_RE = /%/g
+
 export abstract class BaseHistory {
   // previousState: object
   location: HistoryLocation = START
@@ -112,6 +114,37 @@ export abstract class BaseHistory {
     }
   }
 
+  /**
+   * Stringify a URL object
+   * @param location
+   */
+  stringifyURL(location: HistoryURL): string {
+    let url = location.path
+    let query = '?'
+    // TODO: util function?
+    for (const key in location.query) {
+      if (query.length > 1) query += '&'
+      // TODO: handle array
+      query += `${key}=${location.query[key]}`
+    }
+
+    if (query.length > 1) url += query
+
+    return url + location.hash
+  }
+
+  /**
+   * Prepare a URI string to be passed to pushState
+   * @param uri
+   */
+  prepareURI(uri: string) {
+    // encode the % symbol so it also works on IE
+    return uri.replace(PERCENT_RE, '%25')
+  }
+
+  // use regular decodeURI
+  decodeURI = decodeURI
+
   /**
    * ensure the current location matches the external source
    * For example, in HTML5 and hash history, that would be
index 209d5eb1bbc648d0cc01d8097c727e7e71356ae8..f556e0c908a3f5dafe064756d97c247ff158dbba 100644 (file)
@@ -53,6 +53,7 @@ export class HTML5History extends BaseHistory {
   ensureLocation() {}
 
   replace(to: HistoryLocation) {
+    // TODO: standarize URL
     if (to === this.location) return
     cs.info('replace', this.location, to)
     this.history.replaceState(