Skip to Content
微前端设计与实现
book

微前端设计与实现

by Luca Mezzalira
August 2022
Beginner to intermediate
270 pages
7h 38m
Chinese
Posts & Telecom Press
Content preview from 微前端设计与实现
108
5
<h1>
Shop
</h1>
<Switch>
<Route exact path={`${path}`} component={Home}/>
<Route exact path={`${path}/product/:productId`} component={Details}/>
</Switch>
</div>
)
}
// 后置代码
使用
React Router
库,我们首先访问的是
URL
深度的第一级。然后,当用户选择特定产品
时,基于产品
ID
的变化
URL
深度级别会不断地递增。从第二级开始,结构和管理通常
会在微前端内部完全实现,这样,每个子域可以自主发展,在优化功能的时候无须与其他
团队协调。这还可以防止不同的域创建重复的第一级
URL
,因为只有一个团队负责全局路
由。当实现详情页面时,我们可以使用产品
ID
API
请求用于展示的数据:
// 前置代码
const Details = () => {
// 通过URL获取商品ID
const {productId} = useParams()
// 添加一些逻辑从而通过API获取商品详情
return(
<div>
// 显示商品ID
{`Details page, product id: ${productId}`}
<Link to="/shop">All products</Link>
</div>
)
}
// 后置代码
通过这种方式,我们可以轻松地设计代码库,应对未来可能出现的拆分 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Python语言及其应用(第2版)

Python语言及其应用(第2版)

Bill Lubanovic

Publisher Resources

ISBN: 9787115595089