Skip to content

Global Configuration

The app.json file in the root directory of the mini program is used to configure the mini program globally. The file content is a JSON object with the following properties:

Configuration items

PropertiesTypeRequiredDescription
entryPagePathstringNoThe default homepage of the mini program
pagesstring[]YesPage path list
windowObjectNoThe global default window performance
tabBarObjectNoThe global default window performance
debugObjectNoThe performance of the bottom tab bar
subpackagesObjectNoWhether to turn on debug mode, which is closed by default
workersObjectNoSub-package structure configuration
navigateToMiniProgramAppIdListObjectNoThe directory where the Worker code is placed
preloadRuleObjectNoThe list of mini programs that need to be jumped, see Cwx.navigateToMiniProgram
usingComponentsObjectNoGlobal Custom Components Configuration
permissionObjectNoMini program interface permission related settings
darkmodeObjectNoMini program supports DarkMode
themeLocationObjectNoIndicates theme.json Location, darkmode is true and is required
disableSlideCloseGestureObjectNoWhether to disable the gesture of closing the mini program by sliding sideways. The default value is false.

entryPagePath

Specify the default startup path (home page) of the mini program. If not filled in, it will default to the first item in the pages list. Page path parameters are not supported.

js
{
  "entryPagePath": "pages/index/index"
}

pages

Used to specify which pages the mini program consists of. Each item corresponds to the path (including file name) information of a page. The file name does not need to have a file suffix. The framework will automatically find the four files .json, .js, .wxml, and .wxss in the corresponding location for processing.

When entryPagePath is not specified, the first item in the array represents the initial page (home page) of the mini program.

Adding/reducing pages in the mini program requires modifying the pages array.

If the development directory is:

js
├── app.js
├── app.json
├── app.wxss
├── pages
│   │── index
│   │   ├── index.wxml
│   │   ├── index.js
│   │   ├── index.json
│   │   └── index.wxss
│   └── logs
│       ├── logs.wxml
│       └── logs.js
└── utils

You need to write in app.json:

js
{
  "pages": ["pages/index/index", "pages/logs/logs"]
}

window

Used to set the status bar, navigation bar, title, and window background color of the mini program.

Properties
Type
Default value
Description
navigationBarBackgroundColor
HexColor
#000000
Navigation bar background color, such as #000002
navigationBarTextStyle
string
white
Navigation bar title, status bar color, only supports: black / white
navigationBarTitleText
string
-
Navigation bar title text content
navigationStyle
string
default
Navigation bar style, only supports the following values:
  • default default style
  • custom custom navigation bar, only keep the upper right corner pill button
  • hide custom navigation bar, can support privacy navigation bar and pill button. See Note 2 immediately after the table
backgroundColor
HexColor
#ffffff
Window background color
backgroundTextStyle
string
#dark
Pull-down loading style, only supports dark / light
backgroundColorTop
string
#dark
Top window background color, only iOS support
backgroundColorBottom
string
#dark
Top window background color, only iOS support
enablePullDownRefresh
boolean
false
Whether to enable global pull-down refresh
See for details Page.onPullDownRefresh
onReachBottomDistance
number
50
The distance from the bottom of the page when the pull-to-bottom event is triggered, in px
See for details Page.onReachBottom
customNavigateBack
Boolean
false
Whether to intercept the default return of the page (click the tabBar to return or slide or back key to return) and use it in conjunction with Page.onCustomBack
pageOrientation
string
portrait
Screen rotation settings, support auto / portrait / landscape
See for details Response to changes in display area

Note 1: HexColor (hexadecimal color value), such as '#ff00ff'

Note 2: About navigationStyle

  • navigationStyle is only effective in app.json.
  • navigationStyle: custom is invalid for web-view components

tabBar

If the mini program is a multi-tab application (there is a tab bar at the bottom or top of the client window to switch pages), you can specify the performance of the tab bar and the corresponding page displayed when the tab is switched through the tabBar configuration item.

PropertiesTypeRequiredDefault valueDescription
colorHexColorYes-The default color of the text on the tab, only hexadecimal colors are supported
selectedColorHexColorYes-The color of the text on the tab when it is selected, only hexadecimal colors are supported
backgroundColorHexColorYes-The background color of the tab, only hexadecimal colors are supported
borderStylestringNoblackThe color of the top border of the tabbar, only black / white are supported
listArrayYes-The list of tabs, see the list attribute description for details, at least 2 and at most 5 tabs
positionstringNobottomThe position of the tabBar, only bottom / top are supported
custombooleanNofalseCustomize the tabBar, for details, see Customize tabBar

Where list accepts an array, only at least 2 and at most 5 tabs can be configured, the tabs are sorted in the order of the array, each item is an object, and its attribute values

PropertiesTypeRequiredDescription
pagePathstringYesPage path, must be defined in pages first
textstringYesButton text on the tab
iconPathstringNoImage path, icon size limit is 40kb, recommended size is 81px * 81px, network images are not supported
selectedIconPathstringNoWhen position is top, icon is not displayed

debug

You can turn on debug mode in the developer tools. In the console panel of the developer tools, the debugging information is given in the form of info, which includes Page registration, page routing, data update, event triggering, etc. It can help developers quickly locate some common problems.

subpackages

When enabling Package Loading , declare the project subpackage structure.

TIP

It is also supported to write it as subPackages.

workers

When using worker to handle multi-threaded tasks, set the directory where the Worker code is placed.

When the mini program needs to use the navigateToMiniProgram interface to jump to other mini programs, you need to first declare the list of mini program appIds to jump to in the configuration file, and a maximum of 10 are allowed.

preloadRule

Declare Subpackage pre-download rules.

usingComponents

The usingComponents field declared in app.json is considered a global custom component and can be used directly in the page or custom component in the mini program without further declaration.

TIP

Global custom components will be considered to be relied upon by all pages and will be initialized when all pages are started, affecting startup performance and occupying the size of the main package. Custom components that are only referenced by individual pages or subpackages should be declared in the page configuration as much as possible.

permission

Mini program interface permission related settings, field type is Object, structure is:

PropertiesTypeRequiredDescriptionDescription
scope.userLocationPermissionObjectNo-Location related permission declaration

PermissionObject structure

PropertiesTypeRequiredDescriptionDescription
descstringYes-Chinese interface usage description displayed when the mini program obtains permission, up to 80 characters
desc-enstringYes-English interface usage description displayed when the mini program obtains permission, up to 80 characters
desc-adesc-arstringYes-Arabic interface usage description displayed when the mini program obtains permission, up to 80 characters
For example:
js
{
  "pages": ["pages/index/index"],
  "permission": {
    "scope.userLocation": {
      "desc": "Your location information will be used to display the effects of the Mini Program location interface." // Continuous Background Positioning for Freeway Driving
    }
  }
}

scope list

scopeCorresponding interfaceDescription
scope.userinfowx.getUserInfoUser information
scope.userLocationwx.getLocationGet geographic location information.
scope.userFuzzyLocationwx.getFuzzyLocationGet fuzzy geographic location information.
scope.recordlive-pusher or wx.startRecordLive broadcast or recording
scope.cameracameraCamera component
scope.addPhoneCalendarwx.addPhoneCalendarAdd log
scope.writePhotosAlbumwx.saveImageToPhotosAlbumSave pictures to album
scope.bluetoothwx.openBluetoothAdapterBluetooth

darkmode

You can configure 'darkmode': true to indicate that the current mini program can adapt to DarkMode. All basic components will display different default styles according to the system theme, and the navigation bar and tab bar will also automatically switch according to the developer's configuration.

After configuration, please follow the DarkMode Adaptation Guide to complete the adaptation work other than the basic style.

js
{
  "darkmode": true
}

themeLocation

Custom theme.json Path, when configuring 'darkmode':true, the current configuration file is required.

disableSlideCloseGesture

Whether to disable the gesture of sliding to close the mini program, the default is false.

apiVersion

For APIs (for example: wx.login Version control, the latest version is used by default when not configured.

js
{
  "apiVersion": "v1"
}

Configuration example:

js
{
  "pages": ["pages/index/index", "pages/logs/index"],
  "window": {
    "navigationBarTitleText": "Demo"
  },
  "tabBar": {
    "list": [
      {
        "pagePath": "pages/index/index",
        "text": "index"
      },
      {
        "pagePath": "pages/logs/logs",
        "text": "logs"
      }
    ]
  },
  "debug": true
}