I am using vue-router in my vue application. I have the following routes in my application.
const routes = [
{name: "home", path: "/", component: Home},
{name: "user", path: "/user", component: User},
{name: "edit-user", path: "/user/edit", component: EditUser}
];
const router = new VueRouter({
routes: routes,
mode: 'history'
});
Here both the routes are working perfectly when accessed using router-link
as given below.
<router-link to="/user">Go to user</router-link>
<router-link to="/user/edit">Edit user</router-link>
If I am accessing the routes directly by page refresh the route "/user" works perfectly. But the route "/user/edit" shows a black page with just the following error in the console (without any other error details).
Uncaught SyntaxError: Unexpected token <
Can anyone help me out to solve this?
I am using vue-router in my vue application. I have the following routes in my application.
const routes = [
{name: "home", path: "/", component: Home},
{name: "user", path: "/user", component: User},
{name: "edit-user", path: "/user/edit", component: EditUser}
];
const router = new VueRouter({
routes: routes,
mode: 'history'
});
Here both the routes are working perfectly when accessed using router-link
as given below.
<router-link to="/user">Go to user</router-link>
<router-link to="/user/edit">Edit user</router-link>
If I am accessing the routes directly by page refresh the route "/user" works perfectly. But the route "/user/edit" shows a black page with just the following error in the console (without any other error details).
Uncaught SyntaxError: Unexpected token <
Can anyone help me out to solve this?
Share Improve this question edited Mar 14, 2018 at 12:08 Arun D asked Mar 14, 2018 at 11:40 Arun DArun D 2,3875 gold badges30 silver badges41 bronze badges2 Answers
Reset to default 18I was facing the same issue I resolved this by adding
publicPath: '/'
in my Webpack config file suggested on https://github.com/webpack/webpack-dev-middleware/issues/205#issuecomment-315847782
Thanks to Mark M. Muskardin
It was caused due to a very small reason. In my main HTML page, the js file was linked as follows:
<script type="text/javascript" src="js/app.js"></script>
The issue was fixed by changing the src value from "js/app.js"
to "/js/app.js"
as follows:
<script type="text/javascript" src="/js/app.js"></script>