Vue-route+webpack Deploying a single-page routing project with 404 issues with Access refresh

Source: Internet
Author: User

Problem Description:
The front-end colleague uses the Vue.js framework to write a single-page routing project with Vue-route combined with Webpack, which assists in configuring Nginx on the server side. After the deployment is complete, access to the home page is no problem, from the homepage to open two-level pages no problem, but all the two-level page opened, again refreshed, there will be 404 phenomenon! As follows:

Cause of the problem:
The resource accessed when the page was refreshed is not found on the server because the path set by Vue-router is not the actual path.
As above the 404 phenomenon, because in the Nginx configuration root directory/data/app/xqsj_wx/dist below there is no loading this real resource exists, these access resources are rendered in JS.

The first configuration of the service-side Nginx is as follows (assuming the domain name is: testwx.wangshibo.com):
[Email protected] ~]# cat/data/app/nginx/conf/vhosts/testwx.wangshibo.com.conf
server {
Listen 80;

server_name testwx.wangshibo.com;
Root/data/app/xqsj_wx/dist;
Index index.html;

Access_log/var/log/testwx.log main;

}


The reason for the appearance of 404 is because there is no loading in this domain root directory/data/app/xqsj_wx/dist The real directory exists .

Problem solving:
In the Nginx configuration add Vue-route Jump settings (here the first page is index.html, if it is index.php in the following corresponding location replacement), the correct configuration is as follows (add the following red content):
[Email protected] ~]# cat/data/app/nginx/conf/vhosts/testwx.wangshibo.com.conf
server {
Listen 80;

server_name testwx.wangshibo.com;
Root/data/app/xqsj_wx/dist;
Index index.html;

Access_log/var/log/testwx.log main;

Location/{
Try_files $uri $uri/@router;
Index index.html;
}

Location @router {
Rewrite ^.*$/index.html last;
}

}

After restarting Nginx, the problem is solved.

Vue-route+webpack Deploying a single-page routing project with 404 issues with Access refresh

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.