首页 > 解决方案 > 加载在子页面上的 Vue 应用程序的 URL 将更新为站点起始页

问题描述

我正在尝试在我的一个子页面上加载 Vue 应用程序。该站点是在 IIS 上运行 ASP .NET 的 Episerver CMS 站点。

当尝试在我的一个子页面上加载我的 Vue 应用程序时,该 url 更改为我的起始页 url。该应用程序工作正常,但由于 url 已更改,应用程序在页面刷新时中断。

我正在使用具有哈希模式的 Vue 路由器(需要哈希模式。使用历史模式时一切正常)。

假设我的应用程序加载到以下 url:

https://www.example.com/subpage/appstart/

我的路线配置:

{
  mode: 'hash',
  base: '/',
  [
    {
      path: '/',
      name: 'home',
      component: Home
    },
    {
      path: '/page1',
      name: 'page1',
      component: Page
    },
  ],
}

我尝试使用 '/subpage/appstart/' 作为基础,但在使用哈希模式时似乎没有任何效果?

导航到我的应用程序时:

https://www.example.com/subpage/appstart/

网址改为:

https://www.example.com/#/

应用程序有效,路由也有效。导航到其中一个页面最终将使用以下 url:

https://www.example.com/#/page1

如何使应用程序从正确的根 url 工作,以便我的应用程序主页保持在正确的 url 上:

https://www.example.com/subpage/appstart/#/

https://www.example.com/subpage/appstart/#/page1

标签: vue.jsvue-router

解决方案


推荐阅读