Recently in the study review small program development, some of the results of learning to make a note. Reference WeChat applet official documentation: developers.weixin.qq.com/miniprogram…

One, small program configuration

1. Global configuration

The app.json file in the root directory of the applet is used for global configuration of the wechat applet, deciding the path of the page file, window presentation, setting the network timeout, setting the multi-tab, and so on.

// Example {"pages": ["pages/index/index", "pages/logs/index"], "window": {"navigationBarTitleText": "Demo"}, "tabBar": {" a list ": [{" pagePath" : "pages/index/index", "text", "home page"}, {" pagePath ":" pages/logs/index ", "text" : "Log"}]}, "networkTimeout": {"request": 10000, "downloadFile": 10000}, "debug": true}Copy the code

2. Configure the page

Each applet page can also use the same name. Json file to configure the window representation of this page, and the configuration items in the page will overwrite the same configuration items in the window of app.json.

/ / sample {" navigationBarBackgroundColor ":" # FFFFFF ", "navigationBarTextStyle" : "black", "navigationBarTitleText" : "Wechat interface Function demo ", "backgroundColor": "#eeeeee", "backgroundTextStyle": "light"}Copy the code

3. Configure sitemap

Note: The index prompt of sitemap is enabled by default. To disable the index prompt of sitemap, you can set the checkSiteMap field to false in the setting of the project configuration file project.config.json.

The sitemap.json file in the root directory of the applet is used to configure whether the applet and its pages can be indexed by wechat.

There are two ways to configure whether to be indexed by wechat:

1, page included Settings: the index of the whole small program can be closed, small program management background – function – page content access – page included switch;

2. Sitemap configuration: The index of a specific page can be closed.

/ / all pages will be WeChat index (the default) {" rules ": [{" action" : "allow", "page" : "* *"}]} / / path/to/page page not be indexed, The rest will be indexed {" rules ": [{" action" : "disallow", "page" : "the path/to/page"}]}Copy the code

Two, small program five routes

1, wx. NavigateTo ()

Keep the current page and go to a page in the application. Cannot jump to tabbar page. The page stack in the applet can be up to 10 layers, more than wX. redirectTo can be used to jump.

wx.navigateTo({ url:"list? Id =2", events:{id=2", events:{id=2", events:{id=2", events:{id=2", events:{id=2", events:{id=2", events:{id=2", events:{ someEvent:function(data){ console.log(data) } }, Res.evnetchannel. emit('someEvent',{dta:'list'})}})Copy the code

2, wx. RedirectTo ()

The current page is closed and a page in the application is displayed. However, jumping to the Tabbar page is not allowed.

// Example wx.redirectto ({url:'list? id=2', success:function(){}, fail:function(){} })Copy the code

3, wx. SwitchTab ()

Go to the tabBar page and close all other non-Tabbar pages.

wx.switchTab({
    url:'/index'
})
Copy the code

4, wx. NavigateBack ()

Close the current page and return to the previous page or multilevel page. You can use getCurrentPages to get the current stack of pages and determine how many layers you want to return.

Wx. navigateTo({url: 'B? Wx. navigateTo({url: 'C? Wx. NavigateBack ({delta: 2})Copy the code

5, wx. ReLaunch ()

Close all pages and open a page in the application.

// Example wx.relaunch ({url:'list? id=2' })Copy the code

Note: In addition to jump related webView page how to jump back to the applet?

Wx. MiniPrograme. NavigateTo ({url: 'pages/login/login' + 'params'}) / / jump to wx. Small program navigation page miniPrograme. SwitchTab ({ url:"/pages/index/index" })Copy the code