Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
764b1945
Unverified
Commit
764b1945
authored
Sep 03, 2020
by
Jan Potoms
Committed by
GitHub
Sep 03, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make parseRelativeUrl return a UrlObject (#16809)
Alternative to
https://github.com/vercel/next.js/pull/16798
parent
0e843e60
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
5 additions
and
14 deletions
+5
-14
page-loader.ts
packages/next/client/page-loader.ts
+1
-5
router.ts
packages/next/next-server/lib/router/router.ts
+1
-3
parse-relative-url.ts
...s/next/next-server/lib/router/utils/parse-relative-url.ts
+2
-1
prepare-destination.ts
.../next/next-server/lib/router/utils/prepare-destination.ts
+1
-5
No files found.
packages/next/client/page-loader.ts
View file @
764b1945
...
...
@@ -12,7 +12,6 @@ import {
import
getAssetPathFromRoute
from
'../next-server/lib/router/utils/get-asset-path-from-route'
import
{
isDynamicRoute
}
from
'../next-server/lib/router/utils/is-dynamic'
import
{
parseRelativeUrl
}
from
'../next-server/lib/router/utils/parse-relative-url'
import
{
searchParamsToUrlQuery
}
from
'../next-server/lib/router/utils/querystring'
export
const
looseToArray
=
<
T
extends
{}
>
(
input
:
any
):
T
[]
=>
[].
slice
.
call
(
input
)
...
...
@@ -204,10 +203,7 @@ export default class PageLoader {
* @param {string} asPath the URL as shown in browser (virtual path); used for dynamic routes
*/
getDataHref
(
href
:
string
,
asPath
:
string
,
ssg
:
boolean
)
{
const
{
pathname
:
hrefPathname
,
searchParams
,
search
}
=
parseRelativeUrl
(
href
)
const
query
=
searchParamsToUrlQuery
(
searchParams
)
const
{
pathname
:
hrefPathname
,
query
,
search
}
=
parseRelativeUrl
(
href
)
const
{
pathname
:
asPathname
}
=
parseRelativeUrl
(
asPath
)
const
route
=
normalizeRoute
(
hrefPathname
)
...
...
packages/next/next-server/lib/router/router.ts
View file @
764b1945
...
...
@@ -563,7 +563,7 @@ export default class Router implements BaseRouter {
let
parsed
=
parseRelativeUrl
(
url
)
let
{
pathname
,
searchParams
}
=
parsed
let
{
pathname
,
query
}
=
parsed
parsed
=
this
.
_resolveHref
(
parsed
,
pages
)
as
typeof
parsed
...
...
@@ -572,8 +572,6 @@ export default class Router implements BaseRouter {
url
=
formatWithValidation
(
parsed
)
}
const
query
=
searchParamsToUrlQuery
(
searchParams
)
// url and as should always be prefixed with basePath by this
// point by either next/link or router.push/replace so strip the
// basePath from the pathname to match the pages dir 1-to-1
...
...
packages/next/next-server/lib/router/utils/parse-relative-url.ts
View file @
764b1945
import
{
getLocationOrigin
}
from
'../../utils'
import
{
searchParamsToUrlQuery
}
from
'./querystring'
const
DUMMY_BASE
=
new
URL
(
typeof
window
===
'undefined'
?
'http://n'
:
getLocationOrigin
()
...
...
@@ -29,7 +30,7 @@ export function parseRelativeUrl(url: string, base?: string) {
}
return
{
pathname
,
searchParams
,
query
:
searchParamsToUrlQuery
(
searchParams
)
,
search
,
hash
,
href
:
href
.
slice
(
DUMMY_BASE
.
origin
.
length
),
...
...
packages/next/next-server/lib/router/utils/prepare-destination.ts
View file @
764b1945
...
...
@@ -35,7 +35,7 @@ export default function prepareDestination(
parsedDestination
=
{
pathname
,
searchParams
,
query
:
searchParamsToUrlQuery
(
searchParams
)
,
hash
,
protocol
,
hostname
,
...
...
@@ -45,9 +45,6 @@ export default function prepareDestination(
}
}
parsedDestination
.
query
=
searchParamsToUrlQuery
(
parsedDestination
.
searchParams
)
const
destQuery
=
parsedDestination
.
query
const
destPath
=
`
${
parsedDestination
.
pathname
!
}${
parsedDestination
.
hash
||
''
...
...
@@ -108,7 +105,6 @@ export default function prepareDestination(
parsedDestination
.
pathname
=
pathname
parsedDestination
.
hash
=
`
${
hash
?
'#'
:
''
}${
hash
||
''
}
`
delete
parsedDestination
.
search
delete
parsedDestination
.
searchParams
}
catch
(
err
)
{
if
(
err
.
message
.
match
(
/Expected .*
?
to not repeat, but got an array/
))
{
throw
new
Error
(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment