对于单页应用程序,浏览器向后/向前?

时间:2021-09-25 19:40:20

I was working on a Single Page Application(SPA). So to maintain the browser back and forward functionality I am using htmlPushState and window.onpop passing the parameter to change css and call rest APIS from backend.

我正在做一个单页应用程序(SPA)。为了维护浏览器的回传功能,我使用htmlPushState和窗口。onpop传递参数来更改css并从后端调用rest api。

So currently my project has 5 pages under SPA, but I am bit concerned regarding the scalability.

目前我的项目有5页的SPA,但我有点担心的是可伸缩性。

If the project scales will it be difficult to manage back/forward browser clicks?

如果项目规模扩大,是否很难管理回传浏览器点击?

Are there any best practices to be followed for this? Is htmlPushState a good practice to follow?

有什么最佳实践可以遵循吗?htmlPushState是一个好的实践吗?

PS: I am using reactjs in frontend(Is there any way in which I can use reactjs to handle browser back and forwards?)

PS:我在前端使用了堆js(有什么方法可以用堆js来处理前后的浏览器吗?)

2 个解决方案

#1


2  

Since you mentioned reactjs in your tags, I would highly suggest using React Router which supports HTML5 history API. React Router is essentially a wrapper around history package so you can use that as well, depending on your needs.

由于您在标记中提到了堆js,我强烈建议使用支持HTML5 history API的React Router。React Router本质上是一个历史软件包的包装器,因此您也可以使用它,这取决于您的需要。

React Router is one of the most scalable solutions and it works really well in enterprise and consumer facing web sites.

React Router是最可伸缩的解决方案之一,它在面向企业和消费者的web站点上非常有效。

#2


1  

React Router is a complete routing library for React. It has a simple API with powerful features like lazy code loading, dynamic route matching, and location transition handling built right in.

React路由器是一个完整的反应库。它有一个简单的API,具有强大的特性,比如延迟代码加载、动态路由匹配和构建的位置转换处理。

#1


2  

Since you mentioned reactjs in your tags, I would highly suggest using React Router which supports HTML5 history API. React Router is essentially a wrapper around history package so you can use that as well, depending on your needs.

由于您在标记中提到了堆js,我强烈建议使用支持HTML5 history API的React Router。React Router本质上是一个历史软件包的包装器,因此您也可以使用它,这取决于您的需要。

React Router is one of the most scalable solutions and it works really well in enterprise and consumer facing web sites.

React Router是最可伸缩的解决方案之一,它在面向企业和消费者的web站点上非常有效。

#2


1  

React Router is a complete routing library for React. It has a simple API with powerful features like lazy code loading, dynamic route matching, and location transition handling built right in.

React路由器是一个完整的反应库。它有一个简单的API,具有强大的特性,比如延迟代码加载、动态路由匹配和构建的位置转换处理。