我一直在使用历史记录模式,该模式运行良好,并使用了简单的nginx。现在,我添加了动态路由,以便当用户键入baseurl.com/microcosm/anynametheywant时-将它们连接到在本地开发中效果很好的空间,但是当我移到服务器时,我从中得到404,我尝试了一些这里的东西是当前的nginx,router / index.js-仍然无法正常工作,并且仍然返回服务器404,甚至没有组件的帮助
NGINX文件原样
server {
listen 111.111.11.111:80;
server_name *.nodenogg.in;
location / {
try_files $uri $uri/ /index.html;
}
location @rewrites {
rewrite ^(.)$ /index.html last;
}
location ~ /microcosm/\d+$ {
try_files $uri $uri/ /index.html;
}
}
router / index.js
Vue.use(VueRouter)
const routes = [
{
path: '/',
name: 'Home',
component: Home
},
{
path: '/about',
name: 'About',
component: () =>
import(/* webpackChunkName: "about" */ '../views/About.vue')
},
// dynamic segement `:microcosm` is added to the path
{
path: '/microcosm/:microcosm',
component: Home
},
{
path: '*',
name: 'NotFound',
component: NotFound
}
]
const router = new VueRouter({
mode: 'history',
base: base: process.env.VUE_APP_HTTP + '://' + process.env.VUE_APP_URL + '/',
routes
})
export default router
抓取并使用Router.currentRoute.params.microcosm
尝试别名:
location /microcosm {
alias /full/server/path/to/the/vue/dist;
try_files $uri /microcosm/index.html;
}
这是我用于描述的行为的格式。如果配置/路径正确,则访问http://domain/directory时至少应看到一个空白页(无任何尾随路径段)。