github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/ui/src/util/parseSplatParams.ts (about) 1 // Copyright 2020 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 import { Location } from "history"; 12 import { match as Match } from "react-router-dom"; 13 14 /* 15 * parseSplatParams function returns remaining part of the path 16 * after matched part. 17 * ``` 18 * For example: 19 * match.path: `overview/map` 20 * location.path: `overview/map/region=us-west/zone=a` 21 * result: region=us-west/zone=a 22 * ``` 23 */ 24 export function parseSplatParams(match: Match, location: Location) { 25 let splat = location.pathname.replace(`${match.path}`, ""); 26 if (splat.startsWith("/")) { 27 splat = splat.slice(1); 28 } 29 return splat; 30 }