未验证 提交 ec385e57 编写于 作者: J Joe Haddad 提交者: GitHub

Disable optional param routing code paths (#7459)

* Disable optional param routing code paths

* Fix tests
上级 c8a4682d
......@@ -13,9 +13,18 @@ export function getRouteRegex(
/\/\\\$([^\/]+?)(?=\/|$)/g,
(_, $1) => (
(groups[
$1.replace(/\\\$$/, '').replace(/\\([|\\{}()[\]^$+*?.-])/g, '$1')
$1
// // Remove optional parameter marker
// .replace(/\\\$$/, '')
// Un-escape key
.replace(/\\([|\\{}()[\]^$+*?.-])/g, '$1')
] = groupIndex++),
$1.lastIndexOf('$') === $1.length - 1 ? '(?:/([^/]+?))?' : '/([^/]+?)'
// // Test the route for an optional parameter
// $1.lastIndexOf('$') === $1.length - 1
// ? // Optional: match a param
// '(?:/([^/]+?))?'
// : // Required: match a param
'/([^/]+?)'
)
)
......
......@@ -15,11 +15,11 @@ export default () => (
<a id='view-post-1-comment-1'>View comment 1 on post 1</a>
</Link>
<br />
<Link href='/blog/$post/comment/$id$' as='/blog/543/comment'>
<Link href='/blog/$post/comment/$id' as='/blog/543/comment'>
<a id='view-blog-post-1-comments'>View all comments on blog post 543</a>
</Link>
<br />
<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>
</Link>
</div>
......
......@@ -48,7 +48,8 @@ function runTests () {
it('should render optional dynamic page', async () => {
const html = await renderViaHTTP(appPort, '/blog/543/comment')
expect(html).toMatch(/blog post.*543.*comment.*all/i)
// expect(html).toMatch(/blog post.*543.*comment.*all/i)
expect(html).toMatch(/404/i)
})
it('should render nested optional dynamic page', async () => {
......@@ -70,19 +71,19 @@ function runTests () {
}
})
it('should navigate optional dynamic page', async () => {
let browser
try {
browser = await webdriver(appPort, '/')
await browser.elementByCss('#view-blog-post-1-comments').click()
await browser.waitForElementByCss('p')
const text = await browser.elementByCss('p').text()
expect(text).toMatch(/blog post.*543.*comment.*\(all\)/i)
} finally {
if (browser) await browser.close()
}
})
// it('should navigate optional dynamic page', async () => {
// let browser
// try {
// browser = await webdriver(appPort, '/')
// await browser.elementByCss('#view-blog-post-1-comments').click()
// await browser.waitForElementByCss('p')
// const text = await browser.elementByCss('p').text()
// expect(text).toMatch(/blog post.*543.*comment.*\(all\)/i)
// } finally {
// if (browser) await browser.close()
// }
// })
it('should navigate optional dynamic page with value', async () => {
let browser
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册