import { createRouter, createWebHashHistory, createWebHistory, RouteRecordRaw } from 'vue-router';

const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    redirect: 'manual',
  },
  {
    path: '/manual',
    name: 'manual',
    component: () => import("../views/manual/index.vue"),
  },
  {
    path: '/manual/edit',
    name: 'manual-edit',
    component: () => import("../views/manual/edit.vue"),
  },
  {
    path: '/manual/view',
    name: 'manual-view',
    component: () => import("../views/manual/view.vue"),
  },


  // <Route path='/user/new' element={<UserForm />} />
  // <Route path='/user/:id/edit' element={<UserForm />} />
  // <Route path='/user/:id' element={<UserForm />} />

  {
    path: '/editor',
    name: 'editor',
    component: () => import(/* webpackChunkName: "editor" */ "../views/editor/index.vue"),
  },
  {
    path: '/editor/edit',
    name: 'editor-edit',
    component: () => import(/* webpackChunkName: "editor-edit" */ "../views/editor/edit.vue"),
  },
  {
    path: '/editor/view',
    name: 'editor-view',
    component: () => import(/* webpackChunkName: "editor-view" */ "../views/editor/view.vue"),
  },
];
// if (window.__POWERED_BY_QIANKUN__) {
//   routes.forEach(item => {
//     item.path = '/app1' + item.path
//   })
// }

const router = createRouter({
  // history: createWebHistory('/app1'),
  history: createWebHashHistory('/app1'),
  routes,
});
router.beforeEach((to, from, next) => {
  // if (window.history.state === null) {
  //   history.replaceState({
  //     back: from.path,
  //     current: to.path,
  //     forward: null,
  //     position: NaN,
  //     replaced: false,
  //     scroll: null
  //   }, 'http://192.168.2.99:5173/' + to.path);
  // } else {
    if(to.fullPath==='/undefined'){
      next('/manual');
    }else{
      next();
    }
    
  // }
})
export default router;
