Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

基于 vue-router 路由守卫实现路由跳转 #22

Open
Airkro opened this issue Aug 23, 2023 · 1 comment
Open

基于 vue-router 路由守卫实现路由跳转 #22

Airkro opened this issue Aug 23, 2023 · 1 comment

Comments

@Airkro
Copy link

Airkro commented Aug 23, 2023

参考: https://router.vuejs.org/zh/guide/advanced/navigation-guards.html#全局前置守卫

一个自用的方法,能够使小程序代码接近H5原本的vue生态,仅供讨论:

import { createApp } from 'vue';

const App = createApp({});

export default App;
import { createRouter, createWebHistory } from 'vue-router';

const router = createRouter({
  history: createWebHistory(),
  routes: [
    {
      path: '/pages/device/index',
      name: 'device',
    },
  ],
});

router.beforeEach((to) => {
  wx.navigateTo({ url: to.href });
  return false;
});

App.use(router);
import { useRouter } from 'vue-router';
const router = useRouter();

router.push({
    name: 'device',
    query: {
      serial: serialNumber,
    },
});
@Airkro
Copy link
Author

Airkro commented Aug 23, 2023

翻遍 Taro 相关的文档,都没有提到这个方法,个人认为可以取代现有的路由库方案,但暂时没有精力整理成 RFC。如果这里不适合发这个,十分抱歉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant