如何为 VueJS 项目设置根/基本 URL [英] How to Set Root/Base URL for a VueJS Project

查看:29
本文介绍了如何为 VueJS 项目设置根/基本 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将 VueJS 项目部署到像 www.example.com 这样的域,但是,我想将其移动到子文件夹中,以便我可以访问它像 www.example.com/v1

I've deployed a VueJS project to a domain like www.example.com, however, I want to move it to a subfolder so that I can access it like www.example.com/v1

如何设置 VueJS 项目的基本 URL 或根 URL?

How can I set the base URL or root URL of a VueJS project?

注意:这与 Vue-resource

推荐答案

您可以使用 option base as /v1/ 将所有路由移动到 base as /v1/.

You can use option base as /v1/ to move all routes to have base as /v1/.

应用的基本 URL.例如,如果整个单页应用程序都在/app/下提供服务,则 base 应使用值/app/".

The base URL of the app. For example, if the entire single page application is served under /app/, then base should use the value "/app/".

如何将所有路由移动到 嵌套路由,使用父路由为 /v1:

const router = new VueRouter({
  routes: [
    { path: 'v1', component: BaseView,
      children: [
        {
          // UserProfile will be rendered inside BaseView's <router-view>
          // when /v1/profile is matched
          path: 'profile',
          component: UserProfile
        },
        {
          // UserPosts will be rendered inside BaseView's <router-view>
          // when /v1/posts is matched
          path: 'posts',
          component: UserPosts
        }
      ]
    }
  ]
})

这篇关于如何为 VueJS 项目设置根/基本 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆