【发布时间】:2018-08-10 20:56:26
【问题描述】:
我正在尝试在我的 nginx 服务器上设置一个 vue-router。我遇到的问题是,如果我直接将 url 输入到浏览器 myapp.com/mypath,我的路由将不起作用。
我已经尝试了vue router docs 中描述的服务器配置以及堆栈溢出时建议的类似配置。我当前的nginx位置配置如下:
location / {
try_files $uri $uri/ /index.html;
}
location /subscribe {
proxy_pass http://127.0.0.1/subscribe // express API app
}
所做的只是将任何路径重定向到我的根组件(路径:/)而不是/mypath。这确实有道理,location 似乎只重定向到索引文件。如何在我的 VueJS 应用程序中将 myapp.com/mypath 的直接链接重定向到 /mypath 路由?
这是我现在的 vue 路由设置方式:
...
const routes = [
{ path: '/', component: Landing },
{ path: '/mypath', component: MyPath }
];
const router = new VueRouter({ mode: 'history', routes });
new Vue({
el: '#app',
router,
render: h => h(App)
});
【问题讨论】:
-
是的,这是一个错字,但这与我遇到的问题无关。我添加了这个以防万一,以表明我还有其他
location选项。我现在已经更正了 -
您是否尝试过从第一个位置配置中删除
$uri/?我正在使用这个(甚至没有配置任何其他位置顺便说一句),它似乎保留了/mypath附加。
标签: nginx vue.js vuejs2 vue-router