Skip to content

Commit

Permalink
fix(router): loader params 修改适配 multi 模式 fix #12417
Browse files Browse the repository at this point in the history
  • Loading branch information
ZakaryCode committed Sep 20, 2022
1 parent 8f929ac commit 094ecf6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/taro-loader/src/h5.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default function (this: webpack.LoaderContext<any>) {
const pxTransformConfig = options.pxTransformConfig

const pathDirname = dirname(this.resourcePath)
const pageName = isMultiRouterMode ? join(pathDirname, options.name).replace(options.sourceDir + '/', '') : ''
const pageName = isMultiRouterMode ? join(pathDirname, options.filename).replace(options.sourceDir + '/', '') : ''
if (options.bootstrap) {
/** NOTE: Webpack Virtual Module plugin doesn't support triggering a rebuild for webpack5,
* which can cause "module not found" error when webpack5 cache is enabled.
Expand Down Expand Up @@ -83,7 +83,7 @@ applyPolyfills().then(function () {

const components = options.useHtmlComponents ? compatComponentImport || '' : webComponents
const routesConfig = isMultiRouterMode ? `config.routes = []
config.route = ${genResource(pageName, pages, this, options.name)}
config.route = ${genResource(pageName, pages, this, options.filename)}
config.pageName = "${pageName}"` : `config.routes = [
${config.pages?.map(path => genResource(path, pages, this)).join(',')}
]`
Expand Down
3 changes: 3 additions & 0 deletions packages/taro-router/src/router/mpa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ export async function createMultiRouter (
let element
try {
element = await pageConfig.load?.()
if (element instanceof Array) {
element = element[0]
}
} catch (error) {
throw new Error(error)
}
Expand Down

0 comments on commit 094ecf6

Please sign in to comment.