Let’s first look at the problem of 404
The vue project uses the history routing mode. After the page is refreshed, problems such as a white screen with no content, 401, 404, etc. appear. First look at the difference between the two routing modes:
- hash:
http://localhost:8082/#/customer/account
- history:
http://localhost:8082/customer/account
The difference between the two is mainly:
- Routing format.
hash
The mode separates the route by #,history
the mode does not; - Service access.
hash
The mode does not require server configuration and can be accessed directly without reporting errors; buthistory
requires relevant configuration on the server side, otherwise problems such as flashing 404 and 401 will occur.
The system was in the first hash
mode. After changing to history
the mode, 404 appeared on refresh. Therefore, nginx
the configuration was modified. The configuration content is as follows:
server {
listen 18080;
server_name localhost;
# 我们的静态文件部署在根目录的/portal/admin-console/文件夹下,所以配置访问该目录即可
location /portal/admin-console/ {
root app;
index index.html;
# 主要为这一行,解决了404的问题
try_files $uri $uri/ /portal/admin-console/index.html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
404
The meaning is that the interface cannot be found, so when accessing the deployment directory of static files, pass try_files $uri $uri/ /portal/admin-console/index.html;
and locate the files /portal/admin-console/
in the directory . At this time, the access will not work.index.html
404
If it is hash
mode, these configurations are not required. Therefore, if you think about convenience, you can directly choose to use hash
mode instead of history
mode.
Of course, there are some other differences between hash
modes and modes, which can be understood before making conclusions.history
Let's talk about the 401 problem
401 errors are generally net::ERR_ABORTED 401. When accessing the wrong connection, you will find that the error message status is: UNAUTHORIZED
However, there are several reasons for 401, generally including:
- Outdated Browser Cache and Cookies, browser cache or Cookies expired
- Plugin Incompatibility, incompatibility problems caused by
- Incorrect URL or Outdated Link, access connection error, this possibility has a high probability of occurrence
How to fix it?
- Look for Errors in the URL, check if there is an access path error (my problem this time is because the access path is capitalized wrongly...)
- Clear Your Browser's Cache, clear cache
- Flush Your DNS, refresh the DNS cache. It rarely occurs. When the above 1 and 2 are not working, you can try
- Deactivate Your WordPress Plugins, deactivate WordPress Plugins, rarely use it...
- Check the WWW-Authenticate Header Response, check the WWW-Authenticate response header
The above can basically fix the 401 problem. The complete content of the solution comes from https://kinsta.com/knowledgebase/401-error/