UNPKG

743 BJavaScriptView Raw
1/**
2 * react-router v8.0.0
3 *
4 * Copyright (c) Remix Software Inc.
5 *
6 * This source code is licensed under the MIT license found in the
7 * LICENSE.md file in the root directory of this source tree.
8 *
9 * @license MIT
10 */
11//#region lib/server-runtime/urls.ts
12function getNormalizedPath(request) {
13 let url = new URL(request.url);
14 let pathname = url.pathname;
15 if (pathname.endsWith("/_.data")) pathname = pathname.replace(/_\.data$/, "");
16 else pathname = pathname.replace(/\.data$/, "");
17 let searchParams = new URLSearchParams(url.search);
18 searchParams.delete("_routes");
19 let search = searchParams.toString();
20 if (search) search = `?${search}`;
21 return {
22 pathname,
23 search,
24 hash: ""
25 };
26}
27//#endregion
28export { getNormalizedPath };