Skip to content

Commit

Permalink
feat: 去掉对 pages 配置字段的处理,直接作为 ScreenName
Browse files Browse the repository at this point in the history
  • Loading branch information
Pines-Cheng committed Jul 30, 2018
1 parent 746ca09 commit 8d1ff98
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
16 changes: 8 additions & 8 deletions packages/taro-cli/src/rn.js
Expand Up @@ -394,21 +394,21 @@ function parseJSCode (code, filePath) {

if (isEntryFile) {
// import page
pages.forEach(v => {
const pageName = v.startsWith('/') ? v : `/${v}`
const screenName = pageName.replace(/\//g, '')
pages.forEach(pageItem => {
const pagePath = pageItem.startsWith('/') ? pageItem : `/${pageItem}`
const screenName = pagePath.replace(/\//g, '')
const importScreen = template(
`import ${screenName} from '.${pageName}'`,
`import ${screenName} from '.${pagePath}'`,
babylonConfig
)()
node.body.unshift(importScreen)
})
// Taro.initRouter 生成 RootStack
const routerPages = pages
.map(v => {
const pageName = v.startsWith('/') ? v : `/${v}`
.map(pageItem => {
const pageName = pageItem.startsWith('/') ? pageItem : `/${pageItem}`
const screenName = pageName.replace(/\//g, '')
return `['${screenName}',${screenName}]`
return `['${pageItem}',${screenName}]`
})
.join(',')
node.body.push(template(
Expand Down Expand Up @@ -624,7 +624,7 @@ async function build ({watch}) {
await buildTemp()
let t1 = performance.now()
Util.printLog(Util.pocessTypeEnum.COMPILE, `编译完成,花费${Math.round(t1 - t0)} ms`)
// await buildDist({watch})
await buildDist({watch})
if (watch) {
watchFiles()
}
Expand Down
6 changes: 4 additions & 2 deletions packages/taro-router-rn/src/index.js
Expand Up @@ -5,6 +5,8 @@ function getWrappedScreen (Screen, Taro) {
class WrappedScreen extends Screen {
constructor (props, context) {
super(props, context)
// 这样处理不一定合理,
// 有时间看一下 react-navigation 内部的实现机制再优化
Taro.navigateTo = this.wxNavigateTo.bind(this)
Taro.redirectTo = this.wxRedirectTo.bind(this)
Taro.navigateBack = this.wxNavigateBack.bind(this)
Expand All @@ -24,7 +26,7 @@ function getWrappedScreen (Screen, Taro) {
let obj = queryString.parseUrl(url)
console.log(obj)
try {
this.props.navigation.push(obj.url.replace(/\//g, ''), obj.query)
this.props.navigation.push(obj.url, obj.query)
} catch (e) {
fail && fail(e)
complete && complete(e)
Expand All @@ -38,7 +40,7 @@ function getWrappedScreen (Screen, Taro) {
let obj = queryString.parseUrl(url)
console.log(obj)
try {
this.props.navigation.replace(obj.url.replace(/\//g, ''), obj.query)
this.props.navigation.replace(obj.url, obj.query)
} catch (e) {
fail && fail(e)
complete && complete(e)
Expand Down

0 comments on commit 8d1ff98

Please sign in to comment.