当前位置:网站首页>In a single-page app, what is the right way to deal with wrong URLs (404 errors)?
In a single-page app, what is the right way to deal with wrong URLs (404 errors)?
2022-06-25 06:36:00 【javail】
problem :
I am currently writing a web application using angularjs, but I think this question applies to any client-side javascript framework that does routing on the client side ( as angular does ). I am currently using angularjs Write a Web Applications , But I think this problem applies to any client that routes on the client javascript frame ( It's like angular equally ).
In a single-page app, what is the right way to deal with wrong URLs? In a single page application , Handling errors URL What's the right way ?
Looking at a few major sites, I see that gmail will redirect to the inbox if you type any random URL below https://mail.google.com/mail/ . Check out several major sites , I found that if you were https://mail.google.com/mail/ Next Type any random URL,gmail Redirect to inbox .This happens server-side (with an http 300 code) or client-side, depending on whether the wrong path is before or after the # character. This happens on the server side ( Use http 300 Code ) Or client , It depends on the error path # Before or after characters .On the other hand, twitter shows a real HTTP 404 for any invalid URL. On the other hand ,twitter Any invalid... Will be displayed URL The real HTTP 404.A third option would be to show a "soft" 404, a purely client-side error page. The third option is to display “ soft ”404, A pure client error page .
These solutions seem appropriate for different situations. These solutions seem to work in different situations .Twitter wants the links to twitter users and tweets to be real links, so people can share them, post them in news articles, etc, so it is important that invalid links be recognized as such (if I have a broken link to a tweet in my website, a simple crawl will tell me that).Twitter hope Twitter Links between users and tweets are real links , So people can share them , Post them in news articles , Therefore, it is important to identify invalid links ( If I am on my website , A simple crawl would tell me ).In gmail, on the other hand, you are not expected to share links into your inbox, and I'm not even sure if the links are really permanent/persistent: it seems the url updating mostly serves the purpose of browser history navigation within the single-page app. On the other hand , stay gmail in , You won't share links to your inbox , I'm not even sure if these links are really permanent / lasting : Seems to be url Updates are mainly used for browser history navigation single page applications .The third approach of giving soft errors might be appropriate for situations similar to gmail, but where there is no reasonable "default" page. The third method of giving soft errors may be applicable to things like gmail The situation of , But there is no reasonable “ Default ” page .
After this long introduction, here are some specific questions: After such a long introduction , Here are some specific questions :
- Is it ever acceptable to give a "soft" error page instead of a 404 error, or should a single-page app always redirect to a real 404 if a url is invalid? Provide “ soft ” Error page instead of 404 Whether the error is acceptable , Or if url Invalid , Whether a single page application should always redirect to the real 404?
- Gmail's code may be perfectly bugfree, but if it did have a bug leading to invalid links that end up redirecting back to the inbox, that might be even more confusing for users than an error page.Gmail Your code may be completely error free , But if it does have errors that cause invalid links to eventually redirect the recycle bin , So for users , This may be more confusing than the error page .For most web apps out there, that are not as well tested as gmail, would it be better to show an error page? For most web applications , They don't look like gmail That's fully tested , Would it be better to display an error page ?
- To implement real 404s for single-page apps, it seems necessary to duplicate the routing logic on the server-side. To achieve real... For single page applications 404, It seems necessary to replicate the routing logic on the server side .Is there any way around this? Is there any way to solve ?
- When redirecting to a 404, I think the user should be able to see the URL that caused the error, possibly in the URL bar. When redirecting to 404 when , I think the user should be able to see the URL, May be in URL In the bar .With the html5 history api, I think this can be accomplished by simply triggering a reload of the current page (with the wrong url), combined with the server-side routing mentioned above. Use html5 history api, I think this can be done by simply triggering a reload of the current page ( Use the wrong url), In combination with the server-side routing mentioned above .For browsers that do not support this or when using hashbang notation, this does not seem possible. For not supporting this function or using hashbang Symbol browser , It seems impossible .What's the best way to support all browsers? What is the best way to support all browsers ?
Solution :
Reference resources : https://stackoom.com/en/question/100k2边栏推荐
- In depth inventory: 23 vscode plug-in artifacts that improve development efficiency and aesthetics
- Can TCP syn handshake messages transmit data
- What elements are indispensable for the development of the character? What are the stages
- Monitoring access: how to grant minimum WMI access to the monitoring service account
- Uncaught typeerror cannot set properties of undefined (setting 'classname') reported by binding onclick event in jsfor loop
- Viewing Chinese science and technology from the Winter Olympics (V): the Internet of things
- How to deploy locally developed SAP ui5 applications to ABAP servers
- CTFSHOW
- Sleep quality today 67 points
- Research Report on brand strategic management and marketing trends in the global and Chinese preserved fruit market 2022
猜你喜欢

DataX tutorial (10) - hot plug principle of dataX plug-in

DNS domain name system

The elephant turns around and starts the whole body. Ali pushes Maoxiang not only to Jingdong

Ht81293 built in adaptive dynamic boost 20W mono class D power amplifier IC solution

sin(a-b)=sina*cosb-sinb*cosa的推导过程

You can see the classification of SQL injection. SQL injection point /sql injection type /sql injection has several /sql injection point classifications

After unplugging the network cable, does the original TCP connection still exist?

Understand what MTU is
![[short time average zero crossing rate] short time average zero crossing rate of speech signal based on MATLAB [including Matlab source code 1721]](/img/4a/304f262c1c08800aa95f9e2d537e4d.jpg)
[short time average zero crossing rate] short time average zero crossing rate of speech signal based on MATLAB [including Matlab source code 1721]

Location object
随机推荐
[Suanli network] problems and challenges faced by the development of Suanli network
DataX tutorial (10) - hot plug principle of dataX plug-in
BGP - basic concept
What elements are indispensable for the development of the character? What are the stages
Analysis report on investment and financing status and operation benefits of global and Chinese dental industry (2022 Edition)
北京网上开股票账户安全吗?
delphi-UUID
Wechat applet simply realizes chat room function
cos(a-b)=cosa*cosb+sina*sinb的推导过程
Is the number of indexes in a table the more the better?
Why can't GC () free memory- Why does gc() not free memory?
Talk about TCP and UDP
百度地图——入门教程
Metauniverse in 2022: robbing people, burning money and breaking through the experience boundary
Microsoft issued a document to celebrate Net 20th anniversary!
The five minute demonstration "teaches" actors to speak foreign languages and can seamlessly switch languages. This AI dubbing company has just received a round a financing of 20million US dollars
Global and Chinese gallium nitride (GAN) market output value scale forecast and application prospect analysis report 2022
Advantages and disadvantages of using SNMP and WMI polling
Tencent and China Mobile continued to buy back with large sums of money, and the leading Hong Kong stocks "led" the market to rebound?
How to deploy locally developed SAP ui5 applications to ABAP servers