lazyload
search
Search
span n>
首页
Blog
Code
Literature
More
language
lazyload
PHODAL
Home
Blog
Literature
《自己动手设计物联网》
《全栈应用开发:精益实践》
《前端架构:从入门到微前端》
查看标签 lazyload
适用于 Angular Lazyload 下的 RouteReuseStrategy
作者:
Phodal Huang
2018年5月12日 09:44
之前做过一个 Angular 下的路由重用,即记录 SPA 应用的上一个页面的内容。最开始的时候,并没有考虑 Lazyload,因此实现起来就比较简单: ``` export class SimpleReuseStrategy implements RouteReuseStrategy { public static handlers: { [key: string]: DetachedRouteHandle } = {}; public shouldDetach(route: ActivatedRouteSnapshot): boolean { return true; } public store(route: ActivatedRouteSnapshot, handle: DetachedRouteHandle): void { SimpleReuseStrategy.handlers[route.routeConfig.path] = handle; } public shouldAttach(route: ActivatedRouteSnapshot): boolean { return !!route.routeConfig && !!SimpleReuseStrategy.handlers[route.routeConfig.path]; } public retrieve(route: ActivatedRouteSnapshot): DetachedRouteHandle { if (!route.routeConfig) { return null; } return SimpleReuseStrategy.handlers[route.routeConfig.path]; } public shouldReuseRoute(future: ActivatedRouteSnapshot, curr: ActivatedRouteSnapshot): boolean { return future.routeConfig === curr.routeConfig; } } ``` 后来项目中添加了 Lazyload,因此便添加了一个 reusePath 的参数来控制是否缓存,最后实现如下: ``` export class SimpleReuseStrategy implements RouteReuseStrategy { public static handlers: { [key: string]: DetachedRouteHandle } = {}; public shouldDetach(route: ActivatedRouteSnapshot): boolean { if (!!route.data && !!route.data.reusePath) { return true; } return false; } /** 当路由离开时会触发。按reusePath作为key存储路由快照&组件当前实例对象 */ public store(route: ActivatedRouteSnapshot, handle: DetachedRouteHandle): void { SimpleReuseStrategy.handlers[route.data.reusePath] = handle; } /** 若 path 在缓存中有的都认为允许还原路由 */ public shouldAttach(route: ActivatedRouteSnapshot): boolean { if (!!route.data.reusePath && !!SimpleReuseStrategy.handlers[route.data.reusePath]) { return true; } return false; } /** 从缓存中获取快照,若无则返回nul */ public retrieve(route: ActivatedRouteSnapshot): DetachedRouteHandle { if (!!route.data && !!route.data.reusePath) { return SimpleReuseStrategy.handlers[route.data.reusePath]; } return null; } /** 进入路由触发,判断是否同一路由 */ public shouldReuseRoute(future: ActivatedRouteSnapshot, curr: ActivatedRouteSnapshot): boolean { if (future.data && curr.data && future.data.reusePath && curr.data.reusePath) { return future.data.reusePath === curr.data.reusePath; } return false; } } ``` 为了保存路由,需要单独额外的 在 Routing 里 添加一个 key : ``` const routes: Routes = [ { data: { reusePath: 'hello/hello' }, path: 'hello/hello', loadChildren: './hello/hello.module#CheckinModule' } ] ```
标签:
angular
lazyload
spa
更多
arrow_forward
Feeds
RSS
/
Atom
最近文章
从生成动画到可编程产物:在 Harness 中构建 Lottie 创作运行时
面向人机交互设计 Harness:构建以产物为中心的 Agent Loop
从可编程到表现力:构建更好的 Agent 运行时重塑用户体验
Harness Inspector:让 Agent 交付过程可观察、可检查、可追溯
Agent 插件如何走向工程化:Better Harness 的五个实践
从 AGENTS.md 开始:构建 Agent 友好项目的五个步骤
设计流动摩擦:AI 原生团队的核心能力
Piece:将 Coding Agent 的局部构建反馈提速 10x
验证工程:从 Vibe 硬件编程 Loop 到自迭代验证
长程验证:AI Agent 长任务的收敛机制
存档
▶
2026
(8 个月)
八月
(6)
七月
(2)
六月
(1)
五月
(4)
四月
(8)
三月
(11)
二月
(4)
一月
(2)
▶
2025
(12 个月)
十二月
(5)
十一月
(7)
十月
(1)
九月
(2)
八月
(2)
七月
(2)
六月
(1)
五月
(7)
四月
(6)
三月
(6)
二月
(1)
一月
(2)
▶
2024
(12 个月)
十二月
(3)
十一月
(3)
十月
(3)
九月
(5)
八月
(4)
七月
(4)
六月
(1)
五月
(3)
四月
(2)
三月
(5)
二月
(2)
一月
(6)
▶
2023
(12 个月)
十二月
(6)
十一月
(4)
十月
(5)
九月
(4)
八月
(4)
七月
(5)
六月
(7)
五月
(4)
四月
(3)
三月
(9)
二月
(6)
一月
(2)
▶
2022
(12 个月)
十二月
(2)
十一月
(3)
十月
(3)
九月
(2)
八月
(5)
七月
(4)
六月
(3)
五月
(5)
四月
(1)
三月
(2)
二月
(3)
一月
(1)
▶
2021
(12 个月)
十二月
(6)
十一月
(5)
十月
(2)
九月
(4)
八月
(4)
七月
(2)
六月
(4)
五月
(4)
四月
(3)
三月
(4)
二月
(2)
一月
(3)
▶
2020
(12 个月)
十二月
(7)
十一月
(7)
十月
(6)
九月
(7)
八月
(9)
七月
(5)
六月
(5)
五月
(5)
四月
(8)
三月
(5)
二月
(5)
一月
(3)
▶
2019
(12 个月)
十二月
(6)
十一月
(4)
十月
(4)
九月
(5)
八月
(4)
七月
(10)
六月
(3)
五月
(6)
四月
(5)
三月
(7)
二月
(4)
一月
(3)
▶
2018
(12 个月)
十二月
(4)
十一月
(5)
十月
(4)
九月
(3)
八月
(5)
七月
(6)
六月
(3)
五月
(5)
四月
(4)
三月
(5)
二月
(2)
一月
(7)
▶
2017
(12 个月)
十二月
(21)
十一月
(19)
十月
(9)
九月
(4)
八月
(5)
七月
(4)
六月
(5)
五月
(4)
四月
(2)
三月
(3)
二月
(1)
一月
(1)
▶
2016
(12 个月)
十二月
(7)
十一月
(5)
十月
(1)
九月
(2)
八月
(2)
七月
(4)
六月
(4)
五月
(7)
四月
(3)
三月
(7)
二月
(8)
一月
(7)
▶
2015
(12 个月)
十二月
(10)
十一月
(10)
十月
(5)
九月
(10)
八月
(12)
七月
(4)
六月
(7)
五月
(6)
四月
(21)
三月
(9)
二月
(8)
一月
(25)
▶
2014
(12 个月)
十二月
(22)
十一月
(16)
十月
(15)
九月
(14)
八月
(30)
七月
(30)
六月
(12)
五月
(47)
四月
(49)
三月
(29)
二月
(12)
一月
(24)
▶
2013
(9 个月)
十二月
(29)
十一月
(9)
十月
(3)
七月
(4)
六月
(1)
五月
(3)
三月
(17)
二月
(13)
一月
(7)
▶
2012
(3 个月)
十二月
(8)
十一月
(3)
三月
(1)
▶
2011
(1 月)
十月
(1)
▶
2010
(1 月)
十二月
(1)
▶
1991
(1 月)
六月
(1)
展开全部
分类
mac os
(10)
Technology
(11)
Thoughtworks
(14)
Internet Of Things
(41)
Share
(26)
ThinkZone
(37)
Arduino
(9)
Hardware
(30)
Notes
(13)
Pythoner Learn Ruby
(5)
Think Of REWORK
(11)
Android
(27)
OpenSUSE
(6)
Linux
(20)
SEO
(9)
Quick Emacs
(6)
Full Stack
(131)
be-a-geek
(11)
Machine learning
(9)
microservices
(22)
Javascript
(55)
Mobile CMS
(11)
CoAP
(18)
Nodejs
(7)
AWS
(8)
杂谈
(100)
翻译
(7)
Build JavaScript FrameWork
(11)
DSL
(8)
Ionic
(13)
Geo
(7)
GIS
(5)
ReThink
(5)
Hybird
(6)
Architecture
(21)
APP
(11)
serverless
(24)
架构拾集
(7)
架构
(21)
AI
(133)
标签
opensuse
(10)
django
(41)
arduino
(10)
thoughtworks
(18)
centos
(9)
nginx
(18)
java
(10)
SEO
(9)
iot
(47)
iot system
(12)
RESTful
(23)
refactor
(17)
python
(47)
mezzanine
(15)
test
(11)
design
(16)
linux
(14)
tdd
(12)
ruby
(14)
github
(24)
git
(10)
javascript
(52)
android
(36)
jquery
(18)
rework
(13)
markdown
(10)
nodejs
(24)
google
(8)
code
(9)
macos
(9)
node
(11)
think
(8)
beageek
(8)
underscore
(14)
ux
(8)
microservices
(10)
rethink
(9)
architecture
(37)
backbone
(19)
mustache
(9)
requirejs
(11)
CoAP
(21)
aws
(10)
dsl
(9)
ionic
(25)
Cordova
(21)
angular
(16)
react
(14)
ddd
(9)
summary
(9)
growth
(10)
frontend
(14)
react native
(8)
serverless
(32)
rust
(9)
llm
(8)
作者
Phodal Huang
(1106)