【问题标题】:How to Set Root/Base URL for a VueJS Project如何为 VueJS 项目设置 Root/Base URL
【发布时间】:2017-07-28 14:16:19
【问题描述】:

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

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

注意:这与 Vue-resource 的基本 URL 无关

【问题讨论】:

    标签: vuejs2 vue.js


    【解决方案1】:

    您可以使用option base 作为/v1/ 将所有路线移动到具有/v1/ 的基础。

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

    如何将所有路由移至nested route,父路由为/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
            }
          ]
        }
      ]
    })
    

    【讨论】:

    • 嗯。不知道这是否是最好的解决方案。没有其他简单的方法吗?
    • @GijoVarghese 你可以在路由对象中使用base 选项,检查我的更新。
    • 但是如何设置基本 URL?
    • 好的,我已经在路由器中设置了基本 url。但是仍然在构建之后,在 index.html 文件中,资源文件不是以 /v1 开头
    • 是的,它似乎没有像我预期的那样工作,还不确定why
    猜你喜欢
    • 2018-02-10
    • 2015-07-14
    • 1970-01-01
    • 2022-07-21
    • 2012-08-01
    • 2020-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多