首页 > 解决方案 > Vue baseUrl set in vue-router base

问题描述

If I use a baseUrl in vue.config.js eg. '/directory1' i also must have base: '/directory1' when setting up vue-router otherwise it will route to '/'.

I want to be able to reference baseUrl in my vue app so I can have base: baseUrl in my vue router setup, is this possible?

标签: vue.jsvue-router

解决方案


vue.config.js只是一个导出的对象。在自己的代码中导入这个对象来读取baseUrl应该没有问题:

import { baseUrl } from './vue.config.js'

console.log(baseUrl);

推荐阅读