javascript - vue Router 使用 rewrite 指定目录后 一直去不掉 #

 手机用户2602886967 发布于 2022-11-28 00:20

今天早上折腾配置了nginx,目录是指向成功了.但是/#/一直去不掉,求大神指点,

Vue的peizhi

newVue({el:'#app',mode:'history',router,template:'',components:{App}})

这是我的nginx配置,

server{listen80;server_namehello.com;root"C:/www/Aweb/vr29/public_html";location/{indexindex.htmlindex.htmindex.php;#autoindexon;}location/start{try_files$uri$uri//index.html;rewrite^/start/(.*)$/app/public/start/dist/index.htmllast;}location~\.php(.*)${fastcgi_pass127.0.0.1:9000;fastcgi_indexindex.php;fastcgi_split_path_info^((?U).+\.php)(/?.+)$;fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;fastcgi_paramPATH_INFO$fastcgi_path_info;fastcgi_paramPATH_TRANSLATED$document_root$fastcgi_path_info;includefastcgi_params;}}

这个我已经知道了,我的
mode:'history',
写错了地方,
现在问题是,我已经指向过去了,
但是我后面不管输入什么只是在打开App.vue里面的内容,
理由里面的内容不显示
我配置的路由失效了.

现在nginx的配置

server{

listen80;server_namehello.com;root"C:/www/Aweb/vr29/public_html";location/{indexindex.htmlindex.htmindex.php;#autoindexon;}location/start{try_files$uri$uri//index.html?$args;rewrite^/start/(.*)$/app/public/start/dist/index.htmllast;}location=/demo{#try_files$uri$uri//app/public/start/dist/index.html=404;try_files$uri$uri//index.html?$args;}location~\.php(.*)${fastcgi_pass127.0.0.1:9000;fastcgi_indexindex.php;fastcgi_split_path_info^((?U).+\.php)(/?.+)$;fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;fastcgi_paramPATH_INFO$fastcgi_path_info;fastcgi_paramPATH_TRANSLATED$document_root$fastcgi_path_info;includefastcgi_params;}

}

使用:http://hello.com/start,打开编译后的项目,

我现在路由中,有一个Home

exportdefaultnewRouter({mode:'history',routes:[{path:'/',name:'Hello',component:Hello},{path:'/home',name:'Home',component:Home},{path:'/user',name:'User',component:User}]})

我访问http://hello.com/start/home

进不去home组件里

1 个回答
  • 在开发的时候就可以把#去掉了,试试把mode:history写到router里面去,然后重新打包发到服务器
    例如

    constrouter=newVueRouter({mode:'history',routes:[...]})

    vue-router文档

    上面文档链接的内容
    nginx

    location/{try_files$uri$uri//index.html;}
    2022-11-28 00:43 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有