From b5f6ed1332c617f2df83967827d79420fd5d07f7 Mon Sep 17 00:00:00 2001 From: GU Yiling Date: Fri, 20 Jul 2018 23:26:03 +0800 Subject: [PATCH] fix: inject scrollBehavior in a more tolerant way (#3560) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently we cannot define `scrollBehavior` like: ```js scrollBehavior () { // ← we can have space before the parenthesis // ... } ``` Fixed this by using a `RegExp` to be more tolerant. --- lib/app/router.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/app/router.js b/lib/app/router.js index c07a1bc957..dd86d4b680 100644 --- a/lib/app/router.js +++ b/lib/app/router.js @@ -35,7 +35,7 @@ const _routes = recursiveRoutes(router.routes, '\t\t', _components) Vue.use(Router) <% if (router.scrollBehavior) { %> -const scrollBehavior = <%= serialize(router.scrollBehavior).replace('scrollBehavior(', 'function(').replace('function function', 'function') %> +const scrollBehavior = <%= serialize(router.scrollBehavior).replace(/scrollBehavior\s*\(/, 'function(').replace('function function', 'function') %> <% } else { %> if (process.client) { window.history.scrollRestoration = 'manual'