Coder Social home page Coder Social logo

native 路由模式下,主应用 history,子应用 hash,子应用无法跳转到另一个子应用的指定页面 about micro-app HOT 7 CLOSED

Ttou avatar Ttou commented on July 25, 2024
native 路由模式下,主应用 history,子应用 hash,子应用无法跳转到另一个子应用的指定页面

from micro-app.

Comments (7)

bailicangdu avatar bailicangdu commented on July 25, 2024

1、主、子之间的路由系统是完全独立的,无法相互影响,子应用或主应用跳转一个地址后另一方不会主动响应 2、geBaseAppRouter获取的是主应用的router实例,这里是vue-router,所以跳转方式参考vue-router的文档

from micro-app.

Ttou avatar Ttou commented on July 25, 2024

是不是主应用的 vue-router 只能激活到某个子应用首页,不能跳转到其他的页

from micro-app.

Ttou avatar Ttou commented on July 25, 2024

确认下流程,目前从主应用跳转到另一个子应用具体页面:

  • 判断目标子应用是否已激活
    • 是:使用 microApp.router.push 跳转
    • 否:使用 vue-router 先跳转目标子应用,同时下发数据通知子应用跳转到对应页面

from micro-app.

bailicangdu avatar bailicangdu commented on July 25, 2024

确认下流程,目前从主应用跳转到另一个子应用具体页面:

  • 判断目标子应用是否已激活

    • 是:使用 microApp.router.push 跳转
    • 否:使用 vue-router 先跳转目标子应用,同时下发数据通知子应用跳转到对应页面

第一点正确,第二点vue-router直接跳转目标页面即可,子应用会根据url进行渲染的

from micro-app.

Ttou avatar Ttou commented on July 25, 2024

不行,子应用没激活的时候,vue-router 跳不到指定页面,路由需要特殊配置吗

iShot_2024-05-13_16 05 20

import microApp from '@micro-zoe/micro-app'
import type VueRouter from 'vue-router'

interface Options {
  name: string
  path: string
}

export function useJumpApp({ name, path }: Options, router: VueRouter) {
  console.log('跳转子应用', name, path)

  if (!microApp.getActiveApps({ excludeHiddenApp: true }).includes(name)) {
    console.log('子应用未激活,需先渲染')
    // router.push({ name })
    // microApp.setData(name, {
    //   type: 'route-change',
    //   payload: { path: path.replace('/#', '') }
    // })
    router.push({ path: '/vue2/#/dialog' })
  } else {
    console.log('子应用已激活,直接跳转路由')
    microApp.router.push({ name, path })
  }
}

from micro-app.

bailicangdu avatar bailicangdu commented on July 25, 2024

你这不是native模式,是search模式,通过设置defaultPage可以指定默认页面 https://micro-zoe.github.io/micro-app/docs.html#/zh-cn/router?id=%e8%ae%be%e7%bd%ae%e9%bb%98%e8%ae%a4%e9%a1%b5%e9%9d%a2

from micro-app.

Ttou avatar Ttou commented on July 25, 2024

试出来了,vue-router 跳转前需要对路径做编码

import microApp from '@micro-zoe/micro-app'
import type VueRouter from 'vue-router'

interface Options {
  name: string
  path: string
}

export function useJumpApp({ name, path }: Options, router: VueRouter) {
  console.log('跳转子应用', name, path)

  if (!microApp.getActiveApps({ excludeHiddenApp: true }).includes(name)) {
    console.log('子应用未激活,需先渲染')
    router.push({ path: `/${name}?${name}=${encodeURIComponent(path)}` })
  } else {
    console.log('子应用已激活,直接跳转路由')
    microApp.router.push({ name, path })
  }
}

from micro-app.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.