react router 6 官方案例
// The `backgroundLocation` state is the location that we were at when one of
// the gallery links was clicked. If it's there, use it as the location for
// the <Routes> so we show the gallery in the background, behind the modal.
let state = location.state as { backgroundLocation?: Location };
location.state是什么类型,这里看不出来。但是as关键字后面接的是一个类型,即{ backgroundLocation? Location },如果用interface或者type定义类型的写法,会是这样:它定义了一个对象类型,该对象有
backgroundLocation属性,该属性是可选的 (?),是Location类型。所以这句话的意思就是把
location的state属性引用的对象,看作 (treat as){ backgroundLocation?: Location}这样一个类型,并使用state这样一个局部变量来引用(赋值给他)。