From: Eduardo San Martin Morote Date: Sat, 12 Oct 2019 13:04:19 +0000 (+0200) Subject: test(matcher): repeated params X-Git-Tag: v4.0.0-alpha.0~205 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f6807eeca785d5d23dc58b99215a25dc8b685d0b;p=thirdparty%2Fvuejs%2Frouter.git test(matcher): repeated params --- diff --git a/__tests__/matcher.spec.ts b/__tests__/matcher.spec.ts index 238d340c..734a08cb 100644 --- a/__tests__/matcher.spec.ts +++ b/__tests__/matcher.spec.ts @@ -116,6 +116,31 @@ describe('Router Matcher', () => { ) }) + it('resolves an array of params for a repeatable params', () => { + assertRecordMatch( + { path: '/a/:p+', name: 'a', components }, + { name: 'a', params: { p: ['b', 'c', 'd'] } }, + { name: 'a', path: '/a/b/c/d', params: { p: ['b', 'c', 'd'] } } + ) + }) + + it('resolves single params for a repeatable params', () => { + assertRecordMatch( + { path: '/a/:p+', name: 'a', components }, + { name: 'a', params: { p: 'b' } }, + { name: 'a', path: '/a/b', params: { p: 'b' } } + ) + }) + + it('keeps repeated params as a single one when provided through path', () => { + assertRecordMatch( + { path: '/a/:p+', name: 'a', components }, + { path: '/a/b/c' }, + // TODO: maybe it should consistently be an array for repeated params + { name: 'a', params: { p: 'b/c' } } + ) + }) + it('resolves a path with multiple params', () => { assertRecordMatch( { path: '/users/:id/:other', name: 'User', components }, diff --git a/explorations/html5.ts b/explorations/html5.ts index abaaebbf..7dacde96 100644 --- a/explorations/html5.ts +++ b/explorations/html5.ts @@ -139,6 +139,7 @@ const router = new Router({ ], }, { path: '/with-data', component: ComponentWithData, name: 'WithData' }, + { path: '/rep/:a*', component: component, name: 'repeat' }, // { path: /^\/about\/?$/, component }, ], async scrollBehavior(to, from, savedPosition) { diff --git a/src/matcher.ts b/src/matcher.ts index a283776c..387bcd41 100644 --- a/src/matcher.ts +++ b/src/matcher.ts @@ -330,6 +330,7 @@ export class RouterMatcher { /** * Transforms a MatcherLocation object into a normalized location * @param location MatcherLocation to resolve to a url + * @param currentLocation MatcherLocationNormalized of the current location */ resolve( location: Readonly, diff --git a/src/router.ts b/src/router.ts index cb341618..20d63d33 100644 --- a/src/router.ts +++ b/src/router.ts @@ -5,6 +5,7 @@ import { normalizeQuery, HistoryLocationNormalized, START, + NavigationDirection, } from './history/common' import { RouterMatcher } from './matcher' import { @@ -44,7 +45,6 @@ interface ScrollBehavior { export interface RouterOptions { history: RouterHistory routes: RouteRecord[] - // TODO: async version scrollBehavior?: ScrollBehavior } @@ -124,14 +124,14 @@ export class Router { // Maybe we could write the length the first time we do a navigation and use that for direction // TODO: this doesn't work if the user directly calls window.history.go(-n) with n > 1 // We can override the go method to retrieve the number but not sure if all browsers allow that - // if (info.direction === NavigationDirection.back) { - // this.history.forward(false) - // } else { - // TODO: go back because we cancelled, then - // or replace and not discard the rest of history. Check issues, there was one talking about this - // behaviour, maybe we can do better - // this.history.back(false) - // } + if (info.direction === NavigationDirection.back) { + this.history.forward(false) + } else { + // TODO: go back because we cancelled, then + // or replace and not discard the rest of history. Check issues, there was one talking about this + // behaviour, maybe we can do better + this.history.back(false) + } } else { this.triggerError(error, false) }