admin管理员组文章数量:1415684
I have a vuejs project that uses vue router i made a dashboard for my website and i wanted to add a second router to project for it
import Vue from 'vue'
import Router from 'vue-router'
import Index from "@/views/Admin/Index.vue";
import ContactIndex from "@/views/Admin/Contact/Index.vue";
Vue.use(Router)
const router = new Router({
mode: "history",
routes: [{
path: '/admin',
name: 'admin',
ponent: Index,
meta: {
requireAuth: true
}
},
{
path: '/admin/contact',
name: 'contact',
ponent: ContactIndex,
meta: {
requireAuth: true
}
}
]
})
export default router;
the issue is when i tried to open let's say "/admin/contacts" in my browser manually or refreshed the page, contact didn't load up and i got 404 error
BUT, when i click on the router-link tag that is linked to that address it works as intended
How can i fix it?
I have a vuejs project that uses vue router i made a dashboard for my website and i wanted to add a second router to project for it
import Vue from 'vue'
import Router from 'vue-router'
import Index from "@/views/Admin/Index.vue";
import ContactIndex from "@/views/Admin/Contact/Index.vue";
Vue.use(Router)
const router = new Router({
mode: "history",
routes: [{
path: '/admin',
name: 'admin',
ponent: Index,
meta: {
requireAuth: true
}
},
{
path: '/admin/contact',
name: 'contact',
ponent: ContactIndex,
meta: {
requireAuth: true
}
}
]
})
export default router;
the issue is when i tried to open let's say "/admin/contacts" in my browser manually or refreshed the page, contact didn't load up and i got 404 error
BUT, when i click on the router-link tag that is linked to that address it works as intended
How can i fix it?
Share Improve this question asked May 19, 2019 at 19:43 Arshia MoghaddamArshia Moghaddam 5388 silver badges26 bronze badges 1- So the problem is not about vue-router but it's about how do you serve your app, with nginx? the answer will be depend on it. – User 28 Commented May 20, 2019 at 4:33
2 Answers
Reset to default 4If you on development environment and use webpack-dev-server to run your app, you need add historyApiFallback: true
on devServer prop of your webpack config file
If you're not seeing anything on the screen and in the console, You must have some issues with your server configuration (https://router.vuejs/guide/essentials/history-mode.html#example-server-configurations).
To debug, you can have a route to catch all paths. Add the below route into your routes,
{
path: '*',
ponent: function(resolve) {
require(['path/to/NotFoundComponent.vue'], resolve);
}
}
Any URL will load this ponent. Now you can identify what mistakes have been done.
本文标签: javascriptProblem with vue routerhistory mode not working on second layerStack Overflow
版权声明:本文标题:javascript - Problem with vue router, history mode not working on second layer - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745240942a2649326.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论