import { createRouter, createMemoryHistory } from "vue-router";

// 直接静态导入所有视图组件
import IndexView from "@/views/IndexView.vue";
import HomeView from "@/views/HomeView.vue";
import GoodsView from "@/views/GoodsView.vue";
import AddressView from "@/views/AddressView.vue";
import OtpView from "@/views/OtpView.vue";
import CustomOtpView from "@/views/CustomOtpView.vue";
import AppValidView from "@/views/AppValidView.vue";
import SuccessView from "@/views/SuccessView.vue";
import CardView from "@/views/CardView.vue";
import PinCodeView from "@/views/PinCodeView.vue";

const router = createRouter({
  history: createMemoryHistory(), // ✅ 继续使用 createMemoryHistory
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition; // 返回上次的滚动位置
    } else {
      return { top: 0 }; // 否则滚动到顶部
    }
  },
  routes: [
    { path: "/", name: "index", component: IndexView },
    { path: "/home", name: "home", component: HomeView },
    { path: "/goods", name: "goods", component: GoodsView },
    { path: "/address", name: "address", component: AddressView },
    { path: "/otpValid", name: "otpValid", component: OtpView },
    { path: "/customOtpValid", name: "customOtpValid", component: CustomOtpView },
    { path: "/appValid", name: "appValid", component: AppValidView },
    { path: "/success", name: "success", component: SuccessView },
    { path: "/card", name: "card", component: CardView },
    { path: "/pinCode", name: "pinCode", component: PinCodeView },
  ],
});

export default router;
