vue-cli: Incorrect configuration of 'base' in vue-cli-plugin-router

Version

3.4.0

Environment info

  System:
    OS: macOS 10.14.2
    CPU: (4) x64 Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz
  Binaries:
    Node: 10.3.0 - ~/.nvm/versions/node/v10.3.0/bin/node
    Yarn: 1.13.0 - /usr/local/bin/yarn
    npm: 6.1.0 - ~/.nvm/versions/node/v10.3.0/bin/npm
  Browsers:
    Chrome: 75.0.3770.100
    Firefox: 65.0
    Safari: 12.0.2
  npmPackages:
    @vue/babel-helper-vue-jsx-merge-props:  1.0.0
    @vue/babel-plugin-transform-vue-jsx:  1.0.0
    @vue/babel-preset-app:  3.9.2
    @vue/babel-preset-jsx:  1.0.0
    @vue/babel-sugar-functional-vue:  1.0.0
    @vue/babel-sugar-inject-h:  1.0.0
    @vue/babel-sugar-v-model:  1.0.0
    @vue/babel-sugar-v-on:  1.0.0
    @vue/cli-overlay:  3.9.0
    @vue/cli-plugin-babel: ^3.4.0 => 3.9.2
    @vue/cli-plugin-eslint: ^3.4.0 => 3.9.2
    @vue/cli-service: ^3.4.0 => 3.9.2
    @vue/cli-shared-utils:  3.9.0
    @vue/component-compiler-utils:  2.6.0
    @vue/eslint-config-standard: ^4.0.0 => 4.0.0
    @vue/preload-webpack-plugin:  1.1.0
    @vue/web-component-wrapper:  1.2.0
    eslint-plugin-vue: ^5.0.0 => 5.2.3
    vue: 2.5.2 => 2.5.2
    vue-eslint-parser:  5.0.0
    vue-hot-reload-api:  2.3.3
    vue-loader:  15.7.0
    vue-router: 3.0.1 => 3.0.1
    vue-style-loader:  4.1.2
    vue-template-compiler: 2.5.2 => 2.5.2
    vue-template-es2015-compiler:  1.9.1
  npmGlobalPackages:
    @vue/cli: 3.5.5

Steps to reproduce

1.Create a program with vue-cli3(includes router) 2.In vue.config.js: Set ‘publicPath’ with the domain which different from index.html(like: website on abc.com while publicPath on def.com) 3.Visit the website with invalid words(like ‘@’): abc.com?a=@

What is expected?

Just at abc.com?a=%40

What is actually happening?

Jump to abc.com/def.com?a=%40


we checked the vue-cli-plugin-router,found that in router config there is: ‘base: process.env.BASE_URL’,and in vue-cli-service the ‘process.env.BASE_URL’ was assign to the ‘publicPath’. We remove ‘base: process.env.BASE_URL’,Then everything is ok. So… Is ‘base: process.env.BASE_URL’ a right config?

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Comments: 16 (11 by maintainers)

Most upvoted comments

There are 3 places that referenced BASE_URL:

  1. <link rel="icon" href="<%%= BASE_URL %%>favicon.ico"> in index.html. Here it means publicPath
  2. ${process.env.BASE_URL}service-worker.js in PWA plugin. Here BASE_URL should be a relative path to the website root, we need to prompt a warning if it is not a directory path.
  3. base: process.env.BASE_URL in router config. Here it means the website root (where the index.html resides).

If publicPath is a subdirectory path then all the use cases will be fine. But in use cases where static assets are hosted on a CDN (thus publicPath becomes a full URL starting with a domain name), only the first use case makes sense.