From: Eduardo San Martin Morote Date: Tue, 16 Apr 2019 13:05:17 +0000 (+0200) Subject: wip router.push X-Git-Tag: v4.0.0-alpha.0~445 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9c29a3efbb39259a7182ccbfd4bb83d2b9d7f316;p=thirdparty%2Fvuejs%2Frouter.git wip router.push --- diff --git a/src/history/base.ts b/src/history/base.ts index 5bcf6e35..159876c5 100644 --- a/src/history/base.ts +++ b/src/history/base.ts @@ -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 || '') } /** diff --git a/src/router.ts b/src/router.ts index e2e0ca51..afc85349 100644 --- a/src/router.ts +++ b/src/router.ts @@ -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) {}