小编Ale*_*lex的帖子

vue-router、nginx 和直接链接

我正在尝试在我的 nginx 服务器上设置一个 vue-router。我遇到的问题是,如果我将 url 直接输入到浏览器,我的路线将不起作用myapp.com/mypath

我已经尝试过vue 路由器文档中描述的服务器配置以及关于堆栈溢出的建议类似配置。我当前的nginx位置配置如下:

location / {
    try_files $uri $uri/ /index.html;
}

location /subscribe {
    proxy_pass http://127.0.0.1/subscribe // express API app
}
Run Code Online (Sandbox Code Playgroud)

所做的只是将任何路径重定向到我的根组件(路径:)/而不是/mypath. 这确实有意义,并且location似乎只重定向到索引文件。我怎样才能重定向的直接链接myapp.com/mypath/mypath我的VueJS应用程序路径?

这是我现在的 vue 路由设置方式:

...
const routes = [
    { path: '/', component: Landing },
    { path: '/mypath', component: MyPath }
];

const router = new VueRouter({ mode: 'history', routes });

new Vue({
    el: '#app',
    router,
    render: h => …
Run Code Online (Sandbox Code Playgroud)

nginx vue.js vue-router vuejs2

7
推荐指数
2
解决办法
9913
查看次数

标签 统计

nginx ×1

vue-router ×1

vue.js ×1

vuejs2 ×1