Reactjs 我是否可以在不使用状态或redux的情况下获取react路由中的所有访问路径
我是否可以在不使用状态或redux的情况下获取react路由中的所有访问路径 ex>>我在ask中的路由中 问 如果我走另一条路线 阅读 阅读 然后展示 我需要在不使用state或redux存储的情况下git[ask、read、show]列表。仅使用react-route属性/历史记录 是否有支持此功能的库反应路线?是的,您可以。只需使用localStorage来满足这种需求Reactjs 我是否可以在不使用状态或redux的情况下获取react路由中的所有访问路径,reactjs,redux,react-router,react-router-v4,react-router-dom,Reactjs,Redux,React Router,React Router V4,React Router Dom,我是否可以在不使用状态或redux的情况下获取react路由中的所有访问路径 ex>>我在ask中的路由中 问 如果我走另一条路线 阅读 阅读 然后展示 我需要在不使用state或redux存储的情况下git[ask、read、show]列表。仅使用react-route属性/历史记录 是否有支持此功能的库反应路线?是的,您可以。只需使用localStorage来满足这种需求 import { browserHistory } from 'react-router'; //Your route
import { browserHistory } from 'react-router';
//Your router initialization
browserHistory.listen( location => {
const previouslyVisitedPaths = localStorage.getItem("visitedPaths")
let paths
if (previouslyVisistedPaths === null) { // First write to your localStorage
paths = location
} else {
paths += `,${location}` // append new path to it
}
localStorage.setItem("visitedPaths", paths)
});
此代码将在以后为您提供访问路径:
localStorage.getItem("visitedPaths").split(',')
谢谢,我正在寻找一个库来实现这一点。通过它的属性,你认为它存在吗?我不认为有人会实现库,它很容易被几行代码替换