Skip to content

Commit d62a152

Browse files
committed
simplify ssr initialization
1 parent 79d0001 commit d62a152

File tree

3 files changed

+7
-17
lines changed

3 files changed

+7
-17
lines changed

flow/declarations.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ declare module 'path-to-regexp' {
55
}
66
}
77

8+
declare var __VUE_SSR_CONTEXT__: any;
9+
810
declare type RouterOptions = {
911
routes?: Array<RouteConfig>;
1012
mode?: string;

src/history/abstract.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* @flow */
2+
/* globals __VUE_SSR_CONTEXT__ */
23

34
import type VueRouter from '../index'
45
import { History } from './base'
@@ -43,13 +44,10 @@ export class AbstractHistory extends History {
4344
})
4445
}
4546

46-
setInitialRoute (route: Route) {
47-
this.current = route
48-
this.stack = [this.current]
49-
this.index = 0
50-
}
51-
5247
getLocation () {
53-
return '/'
48+
return (
49+
typeof __VUE_SSR_CONTEXT__ !== 'undefined' &&
50+
__VUE_SSR_CONTEXT__.url
51+
) || '/'
5452
}
5553
}

src/index.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,6 @@ export default class VueRouter {
9898
this.go(1)
9999
}
100100

101-
setInitialLocation (location: RawLocation) {
102-
const route = this.match(location)
103-
if (this.history instanceof AbstractHistory) {
104-
this.history.setInitialRoute(route)
105-
}
106-
if (this.app) {
107-
this.app._route = route
108-
}
109-
}
110-
111101
getMatchedComponents (): Array<any> {
112102
if (!this.currentRoute) {
113103
return []

0 commit comments

Comments
 (0)