Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 修复H5路由有 basename和customRoutes 的情况下navigate 报错 #15508

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion packages/taro-router/src/router/spa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,22 @@
if (typeof app.onUnhandledRejection === 'function') {
window.addEventListener('unhandledrejection', app.onUnhandledRejection)
}
RouterConfig.config = config
const handler = new PageHandler(config, history)
const pagesSet = new Set(config.pages || [])
if (handler.router.customRoutes) {

Check warning on line 38 in packages/taro-router/src/router/spa.ts

View check run for this annotation

Codecov / codecov/patch

packages/taro-router/src/router/spa.ts#L38

Added line #L38 was not covered by tests
for (const key in handler.router.customRoutes) {
const path = handler.router.customRoutes[key]
if (typeof path === 'string') {
pagesSet.add(path)

Check warning on line 42 in packages/taro-router/src/router/spa.ts

View check run for this annotation

Codecov / codecov/patch

packages/taro-router/src/router/spa.ts#L40-L42

Added lines #L40 - L42 were not covered by tests
} else {
path.forEach((p) => {
pagesSet.add(p)
})
}
}
}
const pages = Array.from(pagesSet)
RouterConfig.config = { ...config, pages }

Check warning on line 51 in packages/taro-router/src/router/spa.ts

View check run for this annotation

Codecov / codecov/patch

packages/taro-router/src/router/spa.ts#L47-L51

Added lines #L47 - L51 were not covered by tests

routesAlias.set(handler.router.customRoutes)
const basename = handler.router.basename
Expand Down
Loading