官术网_书友最值得收藏!

  • Angular Router
  • Victor Savkin
  • 246字
  • 2021-07-09 19:20:31

Recognizing states

Next, the router will derive a router state from the URL. To understand how this phase works, we need to learn a bit about how the router matches the URL.

The router goes through the array of routes, one by one, checking if the URL starts with a route's path. Here it will check that /inbox/33/messages/44 starts with :folder. It does, since :folder is what is called a variable segment. It is a parameter where normally you'd expect to find a constant string. Since it is a variable, virtually any string will match it. In our case inbox will match it. So the router will set the folder parameter to inbox, then it will take the children configuration items, the rest of the URL 33/messages/44, and will carry on matching. As a result, the id parameter will be set to 33, and, finally, the messages/:id route will be matched with the second id parameter set to 44.

If the taken path through the configuration does not "consume" the whole URL, the router backtracks to try an alternative path. If it is impossible to match the whole URL, the navigation fails. But if it works, the router state representing the future state of the application will be constructed.

A router state consists of activated routes. And each activated route can be associated with a component. Also, note that we always have an activated route associated with the root component of the application.

主站蜘蛛池模板: 阜康市| 金华市| 玉树县| 新郑市| 江陵县| 民县| 内黄县| 武平县| 喀喇沁旗| 中阳县| 嘉定区| 临猗县| 甘洛县| 隆德县| 天峨县| 仁寿县| 苏尼特左旗| 凉城县| 鹤峰县| 扎囊县| 寿光市| 定安县| 天镇县| 萍乡市| 宾阳县| 哈巴河县| 深圳市| 南华县| 宁陵县| 巫溪县| 会宁县| 石狮市| 化州市| 聂拉木县| 合阳县| 托里县| 曲沃县| 溧水县| 清原| 邯郸市| 加查县|