当前位置:网站首页>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边栏推荐
- How to deploy locally developed SAP ui5 applications to ABAP servers
- Single lithium battery 3.7V power supply 2x12w stereo boost audio power amplifier IC combination solution
- Location object
- sin(a+b)=sina*cosb+sinb*cosa的推导过程
- Research Report on global and Chinese vaccine market profit forecast and the 14th five year plan development strategy 2022-2028
- Methods for obtaining some information of equipment
- Handling skills of SQL optimization (2)
- Meta universe is over, Web 3.0 will be fooled again?
- @The difference between notempty, @notnull and @notblank
- Talk about TCP and UDP
猜你喜欢

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

The perfect presentation of Dao in the metauniverse, and platofarm creates a farm themed metauniverse
![[network security] sharing of experience and ideas of an emergency battle](/img/9b/dd6e47ad7610eefd2b8c93602d6a7e.jpg)
[network security] sharing of experience and ideas of an emergency battle

Understand what ICMP Protocol is

Asemi fast recovery diode us1m parameters, us1m recovery time, us1m voltage drop

How to realize hierarchical management of application and hardware in embedded projects

ARM processor operating mode

TCP BBR as rate based
![[v2.0] automatic update system based on motion step API (support disconnection reconnection and data compensation)](/img/73/2ec957d58616d692e571a70826787f.jpg)
[v2.0] automatic update system based on motion step API (support disconnection reconnection and data compensation)

We cannot activate inspection type for article master in transaction code MM41?
随机推荐
[hand torn STL] Stack & queue
Global and China chemical mechanical polishing abrasive materials market demand outlook and investment scale forecast report 2022 Edition
Global and Chinese kaolin market operation scale and investment development proposal report 2022
Pre knowledge of asynchronous operation
Can TCP syn handshake messages transmit data
Count the grid
Highway
Arm instructions and others
Optimal Parking
Face++ realizes face detection by flow
Copying DNA
A + B Again
PHP and WMI – explore windows with PHP
The "&" character will destroy the data stored in the web The "&" character breaks passwords that are stored in the web config
How to open an account online? Is it safe to open an account online?
JS dynamic table creation
[no title] dream notes 2022-02-20
Detailed explanation of @jsoninclude annotation in Jackson
Huawei machine test question: splicing URL
Viewing Chinese science and technology from the Winter Olympics (V): the Internet of things