我可以重定向到不同的路线,但如果我刷新浏览器,该路线将不起作用
I can redirect to a different route, but that route doesn't work if I refresh the browser
通过$router.push({ path:
/week/${year}/${month}/${day}/})
我可以成功route/move(不确定使用什么术语此处)到另一条路线,URL 正确更新。
但是,一旦到达那里,如果我刷新浏览器,路由组件就会变为空(并且没有控制台错误)。
知道这里发生了什么吗?
这是我的路由器代码:
let router = new Router({
mode: 'history',
routes: [
...
{
path: '/',
redirect: '/home',
meta: {
requiresAuth: true
}
},
{
path: '/week/:year/:month/:day',
component: Home,
meta: {
requiresAuth: true
}
},
...
]
})
在使用历史记录模式时,您需要配置用于处理路由器的服务器。
我将 post Apache
和 Nginx
的示例配置,因为它们最常用。
Apache
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
Nginx
location / {
try_files $uri $uri/ /index.html;
}
更多信息可以在官方docs.
上找到
通过$router.push({ path:
/week/${year}/${month}/${day}/})
我可以成功route/move(不确定使用什么术语此处)到另一条路线,URL 正确更新。
但是,一旦到达那里,如果我刷新浏览器,路由组件就会变为空(并且没有控制台错误)。
知道这里发生了什么吗?
这是我的路由器代码:
let router = new Router({
mode: 'history',
routes: [
...
{
path: '/',
redirect: '/home',
meta: {
requiresAuth: true
}
},
{
path: '/week/:year/:month/:day',
component: Home,
meta: {
requiresAuth: true
}
},
...
]
})
在使用历史记录模式时,您需要配置用于处理路由器的服务器。
我将 post Apache
和 Nginx
的示例配置,因为它们最常用。
Apache
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
Nginx
location / {
try_files $uri $uri/ /index.html;
}
更多信息可以在官方docs.
上找到