Skip to Content
Node与Express开发(第2版)
book

Node与Express开发(第2版)

by Ethan Brown
June 2021
Intermediate to advanced
290 pages
9h 21m
Chinese
Posts & Telecom Press
Content preview from Node与Express开发(第2版)
路由
|
159
视图的路由会优先。
要注意,如果你
删除
了一个访问过的视图,这种方法就会出现问题。这个视图将被添加到
autoViews
对象中,因此即使它已经被
删除
,后续的请求也会试图渲染它,这样就出错了。
不过,这个问题是可以解决的,只要使用
try/catch
块把渲染的代码包装起来
,当发现错误
时把视图从
autoViews
中移除即可。我把这个功能增强留作读者的练习。
14.10
 小结
路由是项目的重要组成部分,而路由处理函数可能的组织方式很多,比在这里概括的要多
得多,所以你大可放心地试验,并找出一种适合你以及你的项目的技术。
我鼓励你优先
采用那些既清晰又易于追踪的技术。在外部世界(客户端,通常是浏览器)看来,路由就
像是一张地图,导向响应它的服务器端代码。如果地图错综复杂,就很难追踪应用的信息
流,对开发和调试都将是障碍。
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

面向对象的思考过程(原书第5版)

面向对象的思考过程(原书第5版)

马特 魏斯费尔德
精通模块化JavaScript

精通模块化JavaScript

Nicolás Bevacqua
前端架构设计

前端架构设计

Micah Godbolt

Publisher Resources

ISBN: 9787115565099