Strip queries before matching route on client (#7566)
This commit is contained in:
parent
7132995a0d
commit
fbc20a5401
3 changed files with 14 additions and 1 deletions
|
@ -275,8 +275,9 @@ export default class Router implements BaseRouter {
|
||||||
|
|
||||||
// detect dynamic routing
|
// detect dynamic routing
|
||||||
if (route.indexOf('/$') !== -1) {
|
if (route.indexOf('/$') !== -1) {
|
||||||
|
const { pathname: asPathname } = parse(as)
|
||||||
const rr = getRouteRegex(route)
|
const rr = getRouteRegex(route)
|
||||||
const routeMatch = getRouteMatcher(rr)(as)
|
const routeMatch = getRouteMatcher(rr)(asPathname)
|
||||||
if (!routeMatch) {
|
if (!routeMatch) {
|
||||||
console.error(
|
console.error(
|
||||||
"Your `<Link>`'s `as` value is incompatible with the `href` value. This is invalid."
|
"Your `<Link>`'s `as` value is incompatible with the `href` value. This is invalid."
|
||||||
|
|
|
@ -22,6 +22,10 @@ const Page = () => (
|
||||||
<Link href='/blog/$post/comment/$id' as='/blog/321/comment/123'>
|
<Link href='/blog/$post/comment/$id' as='/blog/321/comment/123'>
|
||||||
<a id='view-nested-dynamic-cmnt'>View comment 123 on blog post 321</a>
|
<a id='view-nested-dynamic-cmnt'>View comment 123 on blog post 321</a>
|
||||||
</Link>
|
</Link>
|
||||||
|
<br />
|
||||||
|
<Link href='/$post?fromHome=true' as='/post-1?fromHome=true'>
|
||||||
|
<a id='view-post-1-with-query'>View post 1 with query</a>
|
||||||
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -58,6 +58,14 @@ function runTests () {
|
||||||
expect(html).toMatch(/blog post.*321.*comment.*123/i)
|
expect(html).toMatch(/blog post.*321.*comment.*123/i)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should render dynamic route with query', async () => {
|
||||||
|
const browser = await webdriver(appPort, '/')
|
||||||
|
await browser.elementByCss('#view-post-1-with-query').click()
|
||||||
|
await waitFor(1000)
|
||||||
|
const url = await browser.eval('window.location.search')
|
||||||
|
expect(url).toBe('?fromHome=true')
|
||||||
|
})
|
||||||
|
|
||||||
it('should navigate to a dynamic page successfully', async () => {
|
it('should navigate to a dynamic page successfully', async () => {
|
||||||
let browser
|
let browser
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in a new issue