From: Eduardo San Martin Morote Date: Fri, 12 Apr 2019 14:52:21 +0000 (+0200) Subject: wip X-Git-Tag: v4.0.0-alpha.0~458 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=74e85f16811ce7200c289fa833f55b05873393c8;p=thirdparty%2Fvuejs%2Frouter.git wip --- diff --git a/src/history/abstract.ts b/src/history/abstract.ts index 93e8460a..9e162018 100644 --- a/src/history/abstract.ts +++ b/src/history/abstract.ts @@ -10,6 +10,7 @@ export class AbstractHistory extends BaseHistory { constructor() { super() + cs.info('created') } // TODO: is this necessary diff --git a/src/history/base.ts b/src/history/base.ts index 767ffffc..eb0a4e3a 100644 --- a/src/history/base.ts +++ b/src/history/base.ts @@ -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 diff --git a/src/history/html5.ts b/src/history/html5.ts index 209d5eb1..f556e0c9 100644 --- a/src/history/html5.ts +++ b/src/history/html5.ts @@ -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(