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
e78c2f44
Commit
e78c2f44
authored
May 14, 2017
by
Arunoda Susiripala
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Introduce proper url routing for next-export which supports query strings.
parent
90991f17
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
12 deletions
+26
-12
link.js
lib/link.js
+3
-5
index.js
lib/router/index.js
+20
-0
router.js
lib/router/router.js
+3
-7
No files found.
lib/link.js
View file @
e78c2f44
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
import
{
resolve
,
format
,
parse
}
from
'url'
import
{
resolve
,
format
,
parse
}
from
'url'
import
React
,
{
Component
,
Children
}
from
'react'
import
React
,
{
Component
,
Children
}
from
'react'
import
PropTypes
from
'prop-types'
import
PropTypes
from
'prop-types'
import
Router
from
'./router'
import
Router
,
{
_rewriteUrlForNextExport
}
from
'./router'
import
{
warn
,
execOnce
,
getLocationOrigin
}
from
'./utils'
import
{
warn
,
execOnce
,
getLocationOrigin
}
from
'./utils'
export
default
class
Link
extends
Component
{
export
default
class
Link
extends
Component
{
...
@@ -126,13 +126,11 @@ export default class Link extends Component {
...
@@ -126,13 +126,11 @@ export default class Link extends Component {
// Add the ending slash to the paths. So, we can serve the
// Add the ending slash to the paths. So, we can serve the
// "<page>/index.html" directly.
// "<page>/index.html" directly.
const
endsWithSlash
=
/
\/
$/
.
test
(
props
.
href
)
if
(
if
(
typeof
__NEXT_DATA__
!==
'undefined'
&&
typeof
__NEXT_DATA__
!==
'undefined'
&&
__NEXT_DATA__
.
nextExport
&&
__NEXT_DATA__
.
nextExport
!
endsWithSlash
)
{
)
{
props
.
href
=
`
${
props
.
href
}
/`
props
.
href
=
_rewriteUrlForNextExport
(
props
.
href
)
}
}
return
React
.
cloneElement
(
child
,
props
)
return
React
.
cloneElement
(
child
,
props
)
...
...
lib/router/index.js
View file @
e78c2f44
...
@@ -85,3 +85,23 @@ export function _notifyBuildIdMismatch (nextRoute) {
...
@@ -85,3 +85,23 @@ export function _notifyBuildIdMismatch (nextRoute) {
window
.
location
.
href
=
nextRoute
window
.
location
.
href
=
nextRoute
}
}
}
}
export
function
_rewriteUrlForNextExport
(
url
)
{
// If there are no query strings
if
(
!
/
\?
/
.
test
(
url
))
{
return
rewritePath
(
url
)
}
const
[
path
,
qs
]
=
url
.
split
(
'?'
)
const
newPath
=
rewritePath
(
path
)
return
`
${
newPath
}
?
${
qs
}
`
function
rewritePath
(
path
)
{
// If ends with slash simply return that path
if
(
/
\/
$/
.
test
(
path
))
{
return
path
}
return
`
${
path
}
/`
}
}
lib/router/router.js
View file @
e78c2f44
...
@@ -5,7 +5,7 @@ import mitt from 'mitt'
...
@@ -5,7 +5,7 @@ import mitt from 'mitt'
import
shallowEquals
from
'../shallow-equals'
import
shallowEquals
from
'../shallow-equals'
import
PQueue
from
'../p-queue'
import
PQueue
from
'../p-queue'
import
{
loadGetInitialProps
,
getURL
}
from
'../utils'
import
{
loadGetInitialProps
,
getURL
}
from
'../utils'
import
{
_notifyBuildIdMismatch
}
from
'./'
import
{
_notifyBuildIdMismatch
,
_rewriteUrlForNextExport
}
from
'./'
export
default
class
Router
{
export
default
class
Router
{
constructor
(
pathname
,
query
,
as
,
{
pageLoader
,
Component
,
ErrorComponent
,
err
}
=
{})
{
constructor
(
pathname
,
query
,
as
,
{
pageLoader
,
Component
,
ErrorComponent
,
err
}
=
{})
{
...
@@ -124,12 +124,8 @@ export default class Router {
...
@@ -124,12 +124,8 @@ export default class Router {
// Add the ending slash to the paths. So, we can serve the
// Add the ending slash to the paths. So, we can serve the
// "<page>/index.html" directly for the SSR page.
// "<page>/index.html" directly for the SSR page.
const
asEndsWithSlash
=
/
\/
$/
.
test
(
as
)
if
(
__NEXT_DATA__
.
nextExport
)
{
if
(
as
=
_rewriteUrlForNextExport
(
as
)
__NEXT_DATA__
.
nextExport
&&
!
asEndsWithSlash
)
{
as
=
`
${
as
}
/`
}
}
this
.
abortComponentLoad
(
as
)
this
.
abortComponentLoad
(
as
)
...
...
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