简体   繁体   English

如何在用php、apache服务器编写的网站子路由上激活vue-router的history模式?

[英]How to activate the history mode of the vue-router on a subrout of a website written in php, apache server?

I am including a SPA on my website in apache server, but when accessing the route of this, I load the views but the route returns to the main domain.我在我的网站上的 apache 服务器中包含了一个 SPA,但是在访问它的路由时,我加载了视图,但路由返回到主域。 How should I configure the router or .htaccess to correct this?我应该如何配置路由器或.htaccess来纠正这个问题?

My website is like www.example.com , and the Vue SPA is located in www.example.com/en/route1/route2/spa .我的网站类似于www.example.com ,Vue SPA 位于www.example.com/en/route1/route2/spa

When I access this route, the Vue SPA loads but the route returns to the main domain www.example.com , and the Vue SPA routes loads as usual but in the main domain route, like www.example.com/spa/spaRoute1 .当我访问此路由时,Vue SPA 加载但路由返回到主域www.example.com ,Vue SPA 路由像往常一样加载但在主域路由中,例如www.example.com/spa/spaRoute1

What I want is to preserve the original route of the Vue SPA, to shows the SPA routes from there, like www.example.com/en/route1/route2/spa/spaRoute1 using the history mode of Vue-Router.我想要的是保留 Vue SPA 的原始路线,从那里显示 SPA 路线,例如使用 Vue-Router 的历史模式的www.example.com/en/route1/route2/spa/spaRoute1

I have tried modify the .htacces like the documentation of vue-router shows but it doesnt help.我已经尝试像 vue-router 显示的文档一样修改.htacces但它没有帮助。

https://router.vuejs.org/guide/essentials/history-mode.html#example-server-configurations https://router.vuejs.org/guide/essentials/history-mode.html#example-server-configurations

I have the router in history mode like this:我的路由器处于历史模式,如下所示:

export default new Router({
    mode: 'history',
   etc....
})

and my .htaccess using the configuration of vue-router docs和我的 .htaccess 使用 vue-router 文档的配置

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteRule ^index\.php$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.php [L]
</IfModule>

you tried using the base property ?你试过使用 base 属性吗? https://router.vuejs.org/api/#base https://router.vuejs.org/api/#base

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM