MCPcopy
hub / github.com/TanStack/router / build

Method build

packages/router-core/src/router.ts:1798–2015  ·  view source on GitHub ↗
(
      dest: BuildNextOptions & {
        unmaskOnReload?: boolean
      } = {},
    )

Source from the content-addressed store, hash-verified

1796 */
1797 buildLocation: BuildLocationFn = (opts) => {
1798 const build = (
1799 dest: BuildNextOptions & {
1800 unmaskOnReload?: boolean
1801 } = {},
1802 ): ParsedLocation => {
1803 // We allow the caller to override the current location
1804 const currentLocation =
1805 dest._fromLocation || this.pendingBuiltLocation || this.latestLocation
1806
1807 // Use lightweight matching - only computes what buildLocation needs
1808 // (fullPath, search, params) without creating full match objects
1809 const lightweightResult = this.matchRoutesLightweight(currentLocation)
1810
1811 // check that from path exists in the current route tree
1812 // do this check only on navigations during test or development
1813 if (
1814 dest.from &&
1815 process.env.NODE_ENV !== 'production' &&
1816 dest._isNavigate
1817 ) {
1818 const allFromMatches = this.getMatchedRoutes(dest.from).matchedRoutes
1819
1820 const matchedFrom = findLast(lightweightResult.matchedRoutes, (d) => {
1821 return comparePaths(d.fullPath, dest.from!)
1822 })
1823
1824 const matchedCurrent = findLast(allFromMatches, (d) => {
1825 return comparePaths(d.fullPath, lightweightResult.fullPath)
1826 })
1827
1828 // for from to be invalid it shouldn't just be unmatched to currentLocation
1829 // but the currentLocation should also be unmatched to from
1830 if (!matchedFrom && !matchedCurrent) {
1831 console.warn(`Could not find match for from: ${dest.from}`)
1832 }
1833 }
1834
1835 const defaultedFromPath =
1836 dest.unsafeRelative === 'path'
1837 ? currentLocation.pathname
1838 : (dest.from ?? lightweightResult.fullPath)
1839
1840 // ensure this includes the basePath if set
1841 const fromPath = this.resolvePathWithBase(defaultedFromPath, '.')
1842
1843 // From search should always use the current location
1844 const fromSearch = lightweightResult.search
1845 // Same with params. It can't hurt to provide as many as possible
1846 const fromParams = Object.assign(
1847 Object.create(null),
1848 lightweightResult.params,
1849 )
1850
1851 // Resolve the next to
1852 // ensure this includes the basePath if set
1853 const nextTo = dest.to
1854 ? this.resolvePathWithBase(fromPath, `${dest.to}`)
1855 : this.resolvePathWithBase(fromPath, '.')

Callers 3

buildAppFunction · 0.80
buildAppFunction · 0.80
buildOnceFunction · 0.80

Calls 15

findLastFunction · 0.90
functionalUpdateFunction · 0.90
decodePathFunction · 0.90
interpolatePathFunction · 0.90
nullReplaceEqualDeepFunction · 0.90
replaceEqualDeepFunction · 0.90
executeRewriteOutputFunction · 0.90
encodePathLikeUrlFunction · 0.90
comparePathsFunction · 0.85
applySearchMiddlewareFunction · 0.85
validateSearchFunction · 0.70

Tested by

no test coverage detected