当前位置: 首页 > 编程日记 > 正文

hitchhiker部署_Hitchhiker的React Router v4指南:无限远的递归路径!

hitchhiker部署

Welcome to the third part of the Hitchhiker’s Guide to React Router v4. In this article we’re going to focus on recursive paths. If you’ve missed the first two parts, you can find part 1 here and part 2 here.

欢迎阅读《 Hitchhiker React Router v4指南》的第三部分。 在本文中,我们将重点介绍递归路径。 如果你已经错过了前两个部分,你可以找到第1部分在这里和第2部分在这里 。

什么是递归路径? (What are recursive paths?)

Recursive paths are nothing more than paths that are composed of nested routes that render the same component to show nested views.

递归路径无非是由嵌套路径组成的路径,这些路径呈现相同的组件以显示嵌套视图。

Example: http://evedes.rockz/Topics/1/2/3/2/1

示例: http://evedes.rockz/Topics/1/2/3/2/1

It’s commonly used to do “breadcrumbs” in websites — a navigation pattern that shows where the user is in a site organic structure, a social network friends relationship tree, solve a lot of complex graph problems, analytics, or trace any kind of information that depends on the last path. This can be the case, for example, of a computer game where you go from one room to another and the path you took to get there needs to be tracked for some reason.

它通常用于在网站上做“面包屑” —一种导航模式,显示用户在站点有机结构中的位置,社交网络朋友关系树,解决许多复杂的图形问题,分析或跟踪任何形式的信息取决于最后一条路。 例如,在一个电脑游戏中,您可能会从一个房间转到另一个房间,而出于某种原因,您需要跟踪到达该房间的路径,就可能是这种情况。

Excited? Say “yeah”! ?

激动吗 说耶”! ?

So, let’s do some changes in our application to test this pattern applied in React Router v4.

因此,让我们在应用程序中进行一些更改以测试在React Router v4中应用的这种模式。

目标 (The Objective)

So, the idea here is to transform our Topic List.

因此,这里的想法是改变我们的主题列表。

Instead of having a list of Topics that are matched and that the user can navigate to and see each Topic Detail and get back (seen in Part I of this guide), let’s do a nested route that starts at Topic 1 and shows the user which Topics are related to it — by showing a list of Links which can be clicked to navigate to the next related Topic Detail. Each time you choose a topic, you can navigate to it, see it’s details, and see which topics are related to it.

让我们做一个嵌套的路由,从主题1开始并向用户显示,该主题没有匹配的主题列表,并且用户可以导航到该主题列表并查看每个主题详细信息并返回(参见本指南的第一部分 )。主题与此相关-通过显示链接列表,可以单击链接以导航到下一个相关的主题详细信息。 每次选择一个主题时,您都可以导航至该主题,查看其详细信息以及与之相关的主题。

routes.js (routes.js)

So in routes.js we’ve deleted the import of the TopicDetails component and corrected the routes to render the TopicList component when the path is /Topics/:topicId, besides the existing Route to /Topics.

因此,在routes.js我们已经删除组件TopicDetails的进口和纠正呈现题目列表组件的路由时的路径是/主题/:topicId,除了现有的布线 /主题

Both will render the same component with different match properties.

两者都会渲染具有不同匹配属性的相同组件。

TopicList.js (TopicList.js)

Besides the small correction above, I’ve heavily refactored the TopicList.js file. Let’s have a look at what we have there:

除了上面的细微修改外,我还大量重构了TopicList.js文件。 让我们来看看我们那里有什么:

We’ve imported Route and Link from the react-router-dom package because we’re going to invoke it later in the code.

我们已从react-router-dom包中导入RouteLink ,因为稍后将在代码中调用它。

We’ve created an array of objects which contains the list of topics. Each topic has a relatedTopics array that promotes the relationship among them.

我们创建了一个包含主题列表的对象数组。 每个主题都有一个relatedTopics数组,可促进它们之间的关系。

We’ve created a find function that receives the topic’s id as an argument and returns the item or topic that corresponds unequivocally to the id passed into it.

我们创建了一个find函数,该函数接收主题ID作为参数,并返回与传递给它的ID明确对应的项目或主题。

The parseInt(id, 10) usage makes sure that even if the argument passed into the find function is a string, it becomes an integer on the base 10 (decimal number system).

parseInt(id,10)的用法可确保即使传递给find函数的参数是一个字符串,它也将成为以10为底的整数(十进制系统)。

Observe that our topics id and relatedTopics values are primitive integers.

请注意,我们的主题idrelatedTopics值是原始整数。

To learn more about parseInt take a look HERE.

要了解有关parseInt的更多信息,请点击这里 。

The component TopicDetail starts by defining the variable topic. This will store the result of the function find which grabs the id that comes from the match object (router) when the component is invoked. It then returns the topic object that corresponds to that id.

组件TopicDetail首先定义变量topic 这将存储函数查找的结果,该结果将在调用组件时获取来自匹配对象(路由器)的ID 。 然后返回主题对象 对应于该id

With that topic object stored, it returns the Details of the topic and creates a dynamic unordered list with the related topics id and name.

存储该主题对象后,它将返回该主题的详细信息 ,并创建一个具有相关主题idname的动态无序列表。

Let’s see this in the browser:

让我们在浏览器中看到这一点:

Nice! It’s working!

真好! 工作正常!

So, when you click one of the links shown, it routes you to the next topic id:

因此,当您单击显示的链接之一时,它将带您到下一个主题id

Wow! This route is outside of the routes.js file! This is new. Observe that technically you can create routes inside any component.

哇! 该路由在routes.js文件之外! 这是新的。 从技术上讲,您可以在任何组件内创建路由。

Do not forget that isExact is false because the url doesn’t entirely match the path from the /Topics/:topicId as previously defined in the routes.js component.

不要忘记isExact为false,因为url/ routes /:topicId中的路径并不完全匹配route.js组件中先前定义的路径

In the end, we define and export the TopicList component which invokes TopicDetail with the match object above. But, as in each instance of TopicDetails when you’re triggering a Route, TopicDetail gets re-rendered with new match properties supplied by the Router at each instance.

最后,我们定义并导出它调用TopicDetail与匹配对象上方的题目列表组件。 但是,就像在触发路由时在TopicDetails的每个实例中一样TopicDetail将使用每个实例中路由器提供的新匹配属性重新呈现。

So now we are done! ?

现在我们完成了! ?

最后但并非最不重要的 (Last but not least)

I think that by this time you already have a good idea on how to start implementing recursive routes.

我认为到这时您已经对如何开始实施递归路由有了一个好主意。

I’ve chosen this example because it’s easy to understand and very useful for some basic stuff.

之所以选择这个示例,是因为它易于理解,并且对某些基本知识非常有用。

The changes I’ve made to the application, to produce this article, can be found in my GitHub repo.

我对应用程序所做的更改(以生成本文)可以在我的GitHub repo中找到。

参考书目 (Bibliography)

To make this article, I’ve used the React Router documentation that you can find here.

为了撰写本文,我使用了React Router文档,您可以在这里找到。

All the other sites I’ve used are linked along the document to add info or provide context to what I’ve tried to explain to you.

我使用过的所有其他网站都与文档链接在一起,以添加信息或提供与我尝试向您解释的内容的上下文。

This article is part 3 of a series called “Hitchhiker’s Guide to React Router v4”

本文是名为“ Hitchhiker的React Router v4指南”系列的第3部分。

  • Part I: Grok React Router in 20min

    第一部分:20分钟内的Grok React Router

  • Part II: [match, location, history] — your best friends!

    第二部分:[比赛,位置,历史]-您最好的朋友!

  • Part IV: route config, the hidden value of defining a route configuration array

    第四部分:路由配置,定义路由配置数组的隐藏值

? Thank you very much!

? 非常感谢你!

翻译自: https://www.freecodecamp.org/news/hitchhikers-guide-to-react-router-v4-21c99a878bf8/

hitchhiker部署

相关文章:

smbpasswd 和 pdbedit 的区别

smbpasswd 和 pdbedit 的区别 以前我们在windows上共享文件的话,只需右击要共享的文件夹然后选择共享相关的选项设置即可。然而如何实现windows和linux的文件共享呢?这就涉及到了samba服务了,这个软件配置起来也不难,使用也非常简…

DB天气app冲刺二阶段第十一天(完结)

今天最后一天冲刺了,明天就不再冲刺了。。已经把所有的技术的问题还有设计的问题都弄好了吧应该说 至少目前来说是的。因为有的实现不了的或者需要耗费时间的已经果断舍弃了,然后需要完善的也都基本完善了。 现在还需要做的就是素材的收集整理。需要抽半…

如何超越console.log并充分利用浏览器的调试控制台

by Gilad Dayagi通过吉拉德达亚吉 The console object is a very useful feature of browsers that has been around for many years. It provides access to the browser’s debugging console.Most web developers know how to print messages to the console using console…

区域设置 ID (LCID) 表, 及获取方法

区域设置 ID (LCID) 表, 及获取方法 中国的区域设置 ID 是 2052, 如果经常打开微软软件的安装目录应该经常见到.获取很简单, 有现成的 API 函数: GetThreadLocale.beginShowMessage(IntToStr(GetThreadLocale)); //2052 end; 区域设置 ID (LCID) 表区域设置描述简写十六进制值十…

E201700525-hm

skeleton n. 骨骼; (建筑物等的) 骨架; 梗概; 骨瘦如柴的人(或动物);adj. 骨骼的; 骨瘦如柴的; 概略的; 基本的; cloud n. 云; 云状物; invoke vt. 乞灵,祈求; 提出或授引…以支持或证明; 召鬼; 借助;render …

php不显示报错

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 error_reporting(E_ALL & ~E_NOTICE);

致谢 开源开发者的贡献_对开源做出的贡献如何使我成为更好的开发人员,以及如何做到这一点...

致谢 开源开发者的贡献by Luciano Strika通过卢西亚诺斯特里卡(Luciano Strika) 对开源做出的贡献如何使我成为更好的开发人员,以及如何做到这一点 (How contributing to open source made me a better developer — and how you can do it, too) So you’ve been …

欲精一行,必先通十行

将前端开发和服务器端开发做一个比较,前端开发没有服务器端开发“深”,服务器端开发没有前端开发“广”。经常听到做前端的同行抱怨需要学的东西太 多,东学一点西学一点,什么都会,但也什么都不精。很直接的结果就是沦为…

LeetCode 228: Summary Ranges

Given a sorted integer array without duplicates, return the summary of its ranges. For example, given [0,1,2,4,5,7], return ["0->2","4->5","7"]. 代码要求对数组中的元素进行分段。 首先给出字符串格式化函数,假设be…

JQ+ajax 提交表单不跳转页面

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 代码 <div class"apply_box"><h1>合作申请</h1><div class"apply_l"><input type"text" maxlength"20" id"name" name&q…

node.js是开源的吗_为开源做贡献并不难:我为Node.js项目做贡献的旅程

node.js是开源的吗As a developer, you should consider contributing to open source software. Many of your potential employers will look favorably on these contributions.作为开发人员&#xff0c;您应该考虑为开源软件做贡献。 您的许多潜在雇主将对这些供款看好。 …

超级简单的jquery轮播图demo

<!DOCTYPE html> <html><head><meta charset"UTF-8"><title>轮播图demo</title><script type"text/javascript" src"js/jquery-3.2.1.slim.js" ></script><link rel"stylesheet" …

Mysql 操作技巧

复制表结构 表数据Mysql> create tables t2 like t1;Mysql> insert into t2 select * from t1; mysql 索引a、Alert Table 用来创建普通索引、Unique 唯一索引 (当前列数值不可重复) 或 Primary Key 主键索引Mysql> alter table table_name add index index_name(col…

JS实现复制到剪切板效果

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 代码&#xff1a; <!DOCTYPE html> <html lang"en"><head><meta http-equiv"Content-Type" content"text/html; charsetutf-8" /><meta cha…

如何管理多个Python版本和虚拟环境

Addition January 2019: If you are coming back to this blog after upgrading to macOS Mojave please see this github issue for a solution to the common pyenv ‘zlib not available’ problem.此外&#xff0c;2019年1月&#xff1a;如果在升级到macOS Mojave之后又回到…

linux 下byte,char,unsigned char的区别

在linux中&#xff0c;对byte的定义为无符号char&#xff0c;而char默认为有符号char。 #ifndef BYTE #define BYTE unsigned char #endif以下ZZ百度知道&#xff1a; 在C中&#xff0c;默认的基础数据类型均为signed&#xff0c;现在我们以char为例&#xff0c;说明(signed) c…

词法作用域和动态作用域

JavaScript采用的是词法作用域 1.词法作用域 即函数定义时&#xff0c;即确定的作用域。js中的作用域链&#xff0c;在函数声明时候&#xff0c;就已经确定了&#xff0c;无论函数在何处调用&#xff0c;其作用域变量的查找都是按照定义是包含关系去查找。 2.动态作用域 变量的…

10-18 JS基础复习笔记

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 1.JS类型 Numbel String Boolean Symbol Null Undefined Object(Funtion,Array,Data,Regexp); 2.字符串转数字类型 "122" //122 var a 1 2; console.log(a) //3 3.null 和 u…

vue.js crud_如何使用VS Code和ADO.NET使用ASP.NET Core执行CRUD操作

vue.js crud介绍 (Introduction) In this article we are going to create a web application using ASP.NET Core MVC with the help of Visual Studio Code and ADO.NET. We will be creating a sample Employee Record Management System and performing CRUD operations on…

redis事物命令示例

命令示例&#xff1a; 1. 事务被正常执行&#xff1a;#在Shell命令行下执行Redis的客户端工具。/> redis-cli#在当前连接上启动一个新的事务。redis 127.0.0.1:6379>multiOK#执行事务中的第一条命令&#xff0c;从该命令的返回结果可以看出&#xff0c;该命令并没有立即执…

JS 函数 函数递归

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 重要&#xff1a;函数也是对象&#xff0c;你可以给它们添加属性或者更改它们的属性。 函数内部对象&#xff1a;arguments 解析&#xff1a;函数实际上是访问了函数体中一个名为 arguments 的内部对象…

swift设置启动图不现实_如何通过装饰房屋来开始在Swift中使用增强现实

swift设置启动图不现实by Ranadhir Dey由Ranadhir Dey 如何通过装饰房屋来开始在Swift中使用增强现实 (How to get started with augmented reality in Swift by decorating your home) If you’ve read my previous post, you already have a beautiful AR floor in your din…

可用于nodejs的SuperAgent(ajax API)

简单示例&#xff1a; import request from superagent;//引用声明 request.post(api).withCredentials()//跨域.end((err, res) > {if (res.ok) {const json JSON.parse(res.text);} else {console.log(获取失败);}}); 1、get 方式 当使用get请求传递查询字符串的时候&…

Java第四次实验

一、实验内容&#xff1a; 结对编程。运行TCP代码&#xff0c;结对进行&#xff0c;一人服务器&#xff0c;一人客户端&#xff1b;利用加解密代码包&#xff0c;编译运行代码&#xff0c;一人加密&#xff0c;一人解密&#xff1b; 集成代码&#xff0c;密后通过TCP发送。 二、…

JS 面向对象编程之原型(prototype)

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 function Person(first, last) {this.first first;this.last last; } Person.prototype.fullName function() {return this.first this.last; } Person.prototype.fullNameReversed function() {…

idea自动捕获_Smilefie:如何通过检测微笑来自动捕获自拍

idea自动捕获by Rishav Agarwal通过里沙夫阿加瓦尔 Smilefie&#xff1a;如何通过检测微笑来自动捕获自拍 (Smilefie: how you can auto-capture selfies by detecting a smile) Ten second takeaway: use Python and OpenCV to create an app that automatically captures a …

hiho 1015 KMP算法 CF 625 B. War of the Corporations

#1015 : KMP算法 时间限制:1000ms单点时限:1000ms内存限制:256MB描述 小Hi和小Ho是一对好朋友&#xff0c;出生在信息化社会的他们对编程产生了莫大的兴趣&#xff0c;他们约定好互相帮助&#xff0c;在编程的学习道路上一同前进。 这一天&#xff0c;他们遇到了一只河蟹&#…

React 组件绑定点击事件,并且传参完整Demo

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 1.传数组下标给点击事件Demo&#xff1a; const A 65 // ASCII character codeclass Alphabet extends React.Component {constructor(props) {super(props);this.handleClick this.handleClick.bind…

ScaleYViewPager

https://github.com/eltld/ScaleYViewPager 转载于:https://www.cnblogs.com/eustoma/p/4572925.html

node mongoose_如何使用Express,Mongoose和Socket.io在Node.js中构建实时聊天应用程序

node mongooseby Arun Mathew Kurian通过阿伦马修库里安(Arun Mathew Kurian) 如何使用Express&#xff0c;Mongoose和Socket.io在Node.js中构建实时聊天应用程序 (How to build a real time chat application in Node.js using Express, Mongoose and Socket.io) In this tut…