Skip to main content

Practice ยท 1 of 2

URL to View State

Write viewFromUrl(url) โ€” parse a full URL (use the URL constructor) and return { route, id, query }. route is the pathname without the leading slash; id is the value of /:id segments for paths like "products/42" (null otherwise); query is an object of searchParams (empty object when none).

Difficulty: intermediate

Back to lesson: Practice: URL & History โ€” Practice