Skip to content

Commit a4a91e7

Browse files
committed
tweak router.resolve API
1 parent 0e0fac9 commit a4a91e7

File tree

10 files changed

+37
-28
lines changed

10 files changed

+37
-28
lines changed

docs/en/SUMMARY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
- [Named Routes](essentials/named-routes.md)
1414
- [Named Views](essentials/named-views.md)
1515
- [Redirect and Alias](essentials/redirect-and-alias.md)
16-
- [Passing props](essentials/passing-props.md)
16+
- [Passing Props to Route Components](essentials/passing-props.md)
1717
- [HTML5 History Mode](essentials/history-mode.md)
1818
- Advanced
1919
- [Navigation Guards](advanced/navigation-guards.md)

docs/en/api/router-instance.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@
4848

4949
``` js
5050
{
51-
normalizedTo: Location;
52-
resolved: Route;
51+
location: Location;
52+
route: Route;
5353
href: string;
5454
}
5555
```

docs/en/essentials/passing-props.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Passing props
1+
# Passing Props to Route Components
22

33
Using `$route` in your component creates a tight coupling with the route which limits the flexibility of the component as it can only be used on certain urls.
44

docs/ja/api/router-instance.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@
4848

4949
``` js
5050
{
51-
normalizedTo: Location;
52-
resolved: Route;
51+
location: Location;
52+
route: Route;
5353
href: string;
5454
}
5555
```

docs/kr/api/router-instance.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@
4545
> 2.1.0+
4646
4747
역방향 URL 해석. `<router-link/>`에서 사용된 것과 같은 형식의 위치가 주어지면 다음과 같이 처리된 속성을 가진 객체를 반환합니다.
48-
48+
4949
``` js
5050
{
51-
normalizedTo: Location;
52-
resolved: Route;
51+
location: Location;
52+
route: Route;
5353
href: string;
5454
}
5555
```

docs/ru/api/router-instance.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@
4848

4949
``` js
5050
{
51-
normalizedTo: Location;
52-
resolved: Route;
51+
location: Location;
52+
route: Route;
5353
href: string;
5454
}
55-
```
55+
```

docs/zh-cn/api/router-instance.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@
4848

4949
``` js
5050
{
51-
normalizedTo: Location;
52-
resolved: Route;
51+
location: Location;
52+
route: Route;
5353
href: string;
5454
}
5555
```

src/components/link.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,20 @@ export default {
3030
render (h: Function) {
3131
const router = this.$router
3232
const current = this.$route
33-
const { normalizedTo, resolved, href } = router.resolve(this.to, current, this.append)
33+
const { location, route, href } = router.resolve(this.to, current, this.append)
3434
const classes = {}
3535
const activeClass = this.activeClass || router.options.linkActiveClass || 'router-link-active'
36-
const compareTarget = normalizedTo.path ? createRoute(null, normalizedTo) : resolved
36+
const compareTarget = location.path ? createRoute(null, location) : route
3737
classes[activeClass] = this.exact
3838
? isSameRoute(current, compareTarget)
3939
: isIncludedRoute(current, compareTarget)
4040

4141
const handler = e => {
4242
if (guardEvent(e)) {
4343
if (this.replace) {
44-
router.replace(normalizedTo)
44+
router.replace(location)
4545
} else {
46-
router.push(normalizedTo)
46+
router.push(location)
4747
}
4848
}
4949
}

src/index.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export default class VueRouter {
123123

124124
getMatchedComponents (to?: RawLocation): Array<any> {
125125
const route = to
126-
? this.resolve(to).resolved
126+
? this.resolve(to).route
127127
: this.currentRoute
128128
if (!route) {
129129
return []
@@ -140,19 +140,25 @@ export default class VueRouter {
140140
current?: Route,
141141
append?: boolean
142142
): {
143+
location: Location,
144+
route: Route,
145+
href: string,
146+
// for backwards compat
143147
normalizedTo: Location,
144-
resolved: Route,
145-
href: string
148+
resolved: Route
146149
} {
147-
const normalizedTo = normalizeLocation(to, current || this.history.current, append)
148-
const resolved = this.match(normalizedTo, current)
149-
const fullPath = resolved.redirectedFrom || resolved.fullPath
150+
const location = normalizeLocation(to, current || this.history.current, append)
151+
const route = this.match(location, current)
152+
const fullPath = route.redirectedFrom || route.fullPath
150153
const base = this.history.base
151154
const href = createHref(base, fullPath, this.mode)
152155
return {
153-
normalizedTo,
154-
resolved,
155-
href
156+
location,
157+
route,
158+
href,
159+
// for backwards compat
160+
normalizedTo: location,
161+
resolved: route
156162
}
157163
}
158164

types/router.d.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,12 @@ declare class VueRouter {
3030
getMatchedComponents (to?: RawLocation): Component[];
3131
addRoutes (routes: RouteConfig[]): void;
3232
resolve (to: RawLocation, current?: Route, append?: boolean): {
33+
location: Location;
34+
route: Route;
35+
href: string;
36+
// backwards compat
3337
normalizedTo: Location;
3438
resolved: Route;
35-
href: string;
3639
};
3740

3841
static install: PluginFunction<never>;

0 commit comments

Comments
 (0)