Im using vue-router in vue.js. It works fine when Im running it as a local server but as soon as I uploading it to my webserver and enter a page directly it results in "Not found" error,
This works fine running as local server: http://192.168.2.118:8080/page2
But this: https://www.mypage.com/page2
results in
Not Found The requested URL was not found on this server.
I have got mode set to "history" to get rid of the # in the url but doesnt seems to have anything to do with the.
Has it anything to do with my webserver?
this is the code in my router.js
export default new Router({
mode: "history",
base: process.env.BASE_URL,
routes: [
{
path: "/",
name: "page1",
component: Page1
},
{
path: "/page2",
name: "page2",
component: () =>
import(/* webpackChunkName: "home" */ "./views/Page2.vue")
}
]
});
This is the full repo for the project: https://github.com/reppoper/forumpost
SOLUTION:
I found a solution by putting this .htaccess file in the root folder. No everything works as expected:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>