javascript - vue Router 使用 rewrite 指定目录后 一直去不掉 #
淡淡烟草味
淡淡烟草味 2017-05-16 13:03:26
[PHP讨论组]

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

Vue的peizhi

new Vue({
    el: '#app',
    mode: 'history',
    router,
    template: '<App/>',
    components: {App}
})

这是我的nginx 配置 ,

server {
        listen       80;
        server_name  hello.com ;
        root   "C:/www/Aweb/vr29/public_html";
        location / {
            index  index.html index.htm index.php;
            #autoindex  on;
        }
        location  /start {
            try_files $uri $uri/ /index.html;
            rewrite ^/start/(.*)$ /app/public/start/dist/index.html last;
        }
        location ~ \.php(.*)$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param  PATH_INFO  $fastcgi_path_info;
            fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
            include        fastcgi_params;
        }
}

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

现在nginx的配置

server {

    listen       80;
    server_name  hello.com ;
    root   "C:/www/Aweb/vr29/public_html";
    location / {
        index  index.html index.htm index.php;
        #autoindex  on;
    }
    location  /start {
        try_files $uri $uri/ /index.html?$args;
        rewrite ^/start/(.*)$ /app/public/start/dist/index.html last;
    }
    location  = /demo {
        #try_files $uri $uri/ /app/public/start/dist/index.html =404;
        try_files $uri $uri/ /index.html?$args;
    }
    location ~ \.php(.*)$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_param  PATH_INFO  $fastcgi_path_info;
        fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
        include        fastcgi_params;
    }

}

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

我现在路由中,有一个Home

export default new Router({
    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里面去,然后重新打包发到服务器
例如

const router = new VueRouter({ 
    mode: 'history',
    routes: [...] 
})

vue-router文档

上面文档链接的内容
nginx

location / { 
    try_files $uri $uri/ /index.html; 
}
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号