什么是路由?为什么是“路由"?需要在单页 Web 应用程序中使用吗? [英] What is routing? Why is "routing" needed in single page web apps?

查看:55
本文介绍了什么是路由?为什么是“路由"?需要在单页 Web 应用程序中使用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解 SPA 的路由库,例如 https://github.com/ReactTraining/react-router 帮助解析 URL 并将应用程序置于状态机的相应状态.

I understood that routing libraries for SPAs like https://github.com/ReactTraining/react-router help to parse the URL and put the app into a corresponding state of a state machine.

还有比这更多的路由吗?

Is there more to routing than this?

为什么首先需要路由?

为什么网址很重要?例如,在桌面应用中没有网址,那么在网络应用中它们有什么大不了的?

Why are URLs important? For example in a desktop app there are no URLs, so what's the big deal about them in a web app?

推荐答案

我也有这个问题:为什么我们需要路由?".您可以完全不用路由来编写应用程序.代码可能会变得混乱,但仍然不是不可能.

I also have this problem: "Why do we need routing?". You can write apps without routing at all. The code can get messy but still, it is not impossible.

我使用路由的最大原因是,如果用户点击浏览器的后退按钮(也就是前进按钮),他将不会在应用内导航.用户可能希望使用他之前加载的不同页面"的历史记录在应用程序中导航.相反,他将被踢出网络应用程序.点击刷新按钮也会将他带到应用程序的根目录.

My biggest reason for having routing is because if the user hits the Back button of the browser (Forward button as well, for that matter), he will not be navigating within the app. The user might expect to navigate within the app using the history of the different "pages" he loaded previously. Instead, he will be thrown out of the web app. Hitting the Refresh button would also throw him to the root of the app.

从用户的角度来看,它是一个普通的网络应用程序(他不需要知道它是如何设计的:SPA 或其他),它应该像任何网络应用程序/网站一样工作.路由确保了这一点,不是吗?

From the user's point of view, it is a regular web app (he doesn't need to know how it is designed: SPA or otherwise) and it should work as any web app/website should work. Routing ensures this, doesn't it?

这篇关于什么是路由?为什么是“路由"?需要在单页 Web 应用程序中使用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆