123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- import { autoSubcrebe } from './utils'
- const tabRoutes = {
- // home: "/pages/index/index",
- // my: "/pages/my/my",
- // chatList: "/pages/chat-list/chat-list",
- }
- const routes = {
- select: "/pages/select/index",
- example: "/pages/example/index",
- camera: "/pages/camera/index",
- index: "/pages/index/index",
- start: "/pages/start/index",
- work: "/pages/work/index"
- }
- function sortQuery (query) {
- return Object.keys(query).map(key => `${key}=${query[key]}`).join('&')
- }
- function toUrl (url, query) {
- if (query) {
- query = sortQuery(query)
- }
- if (tabRoutes[url]) {
- wx.switchTab({
- url: `${tabRoutes[url]}?${query}`,
- })
- } else {
- wx.navigateTo({
- url: `${routes[url]}?${query}`,
- })
- }
- }
- export default {
- tabRoutes,
- push (options) {
- // autoSubcrebe()
- if (typeof options === 'string') {
- return toUrl(options)
- }
- const { url, query } = options
- return toUrl(url, query)
- },
- redirectTo(options){
- const { url, query } = options
- let q = query
- if (q) {
- q = sortQuery(q)
- }
- return (()=>{
- wx.redirectTo({
- url: `${routes[url]}?${q}`,
- })
- })()
- },
- back () {
- wx.navigateBack()
- }
- }
|