六角學院 - HexSchool
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Help
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    2
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    :::info 本文件連結:https://hackmd.io/PAdQKvB0TEeXy0oFhMjcVg 此為 2025 Vue3 前端新手營課程資料,相關資源僅授權給該課程學員。 ::: # 第五週:Vue Router 與 Todolist 全攻略 - 提醒老師錄影 ### 額外課程介紹: - JS 直播班:https://www.hexschool.com/courses/js-training.html - JS&React 直播班:https://www.hexschool.com/courses/js-react-training-2025.html ## 今日主要主題 - Router ### Router - 路由是什麼(路由表概念) ![image](https://hackmd.io/_uploads/rkuCwZQj0.png) ``` npm create vite@latest ``` - 路由結構配置 → 基本頁面結構配置 - 如何配置 router 檔案 - router-view - router-link 連結方式 ## 路由設定要點: 原本是使用 createWebHistory,當選擇此模式會使得無法部署至 GitHub Pages 如果有辦法調整 Server 環境,則可以參考此[文件](https://router.vuejs.org/zh/guide/essentials/history-mode.html#HTML5-%E6%A8%A1%E5%BC%8F)的方法。 ```jsx import { createRouter, createWebHistory } from 'vue-router' const router = createRouter({ history: createWebHistory(import.meta.env.BASE_URL), ... }) ``` 如果要部署至 GitHub Pages,則可以建議換成 **createWebHashHistory** 的模式,`router/indexs.js`。 ```jsx import { createRouter, createWebHashHistory } from 'vue-router' const router = createRouter({ history: createWebHashHistory(import.meta.env.BASE_URL), ... }) ``` ## 路由基本手法 1. 開新頁面 XxxView.vue 2. 撰寫路由表 router/index.js 3. 提供連結方法 routerLink ## 常見路由結構 1. 基本路由 2. 巢狀路由 → 主要用為版型重複運用 - 巢狀路由 → 巢狀連結 router/index.js ```jsx { path: '/nest-router', component: () => import('../views/NestRouter.vue'), children: [ // ... ] } ``` vue file ```jsx <template> <h1>巢狀路由</h1> <RouterView /> </template> ``` 3. 動態路由(本次作業不會用到,但業界常見) - 動態路由 → 動態參數([範例網址](https://randomuser.me/api?seed=1)) router/index.js ```jsx { path: ':id', component: () => import('../views/DynamicRouter.vue') } ``` vue file ```jsx <script setup> import { useRoute } from 'vue-router' const route = useRoute() console.log('router:', route); const { id } = route.params; // 網址上的值 </script> ``` ## 路由方法與狀態 - 路由狀態 useRoute - [https://router.vuejs.org/zh/guide/essentials/dynamic-matching.html#响应路由参数的变化](https://router.vuejs.org/zh/guide/essentials/dynamic-matching.html#%E5%93%8D%E5%BA%94%E8%B7%AF%E7%94%B1%E5%8F%82%E6%95%B0%E7%9A%84%E5%8F%98%E5%8C%96) ```jsx= // DynView.vue <template> <h1>編號:{{ id }}</h1> {{ person }} </template> <script setup> import { useRoute} from 'vue-router' import { ref,onMounted} from 'vue'; import axios from "axios" const route = useRoute() console.log('router:', route); const { id } = route.params; // 網址上的值 const person = ref("") console.log(person.value); onMounted(async () => { const data = await axios.get(`https://randomuser.me/api/?seed=${id}`); person.value = data.data.results[0]; }); </script> ``` - 路由方法 useRouter ## router.push 轉頁 ```jsx= import { useRoute,useRouter} from 'vue-router' const router = useRouter(); //router.push('/about'); ``` - 404 ```jsx { path: '/:pathMatch(.*)*', name: 'NotFound', component: NotFound }, ``` - default link ``` { path: '*', redirect: '/', }, ``` ## 定義自己的路由配置 1. 請先定好完整路由架構 2. 將路由配置對應所有頁面,開發順序: 1. 先開頁面檔案 2. 撰寫路由配置 3. 補上 router-link - 登入頁面 /login (不驗證) - 前端頁面 (需驗證) - todo ## 補充:pathMatch 404 頁面:https://router.vuejs.org/guide/essentials/dynamic-matching#Catch-all-404-Not-found-Route ## 最終任務: - 設計稿:https://www.figma.com/design/MFSk8P5jmmC2ns9V9YeCzM/TodoList?node-id=0-1&t=KzEgeE3s3r6JIPh6-1 - CSS 範例:https://codepen.io/hexschool/pen/qBzEMdm - 同時挑戰證書任務: - [最終挑戰 - Todolist 新手證書任務](https://rpg.hexschool.com/#/training/12062817613334763749/board/content/12062817613334763750_12062817613334763761?tid=12062817613343793193) - [最終挑戰 - Todolist API 整合證書任務](https://rpg.hexschool.com/#/training/12062817613334763749/board/content/12062817613334763750_12062817613334763761?tid=12062817613343793192) > 提醒: > 最終證書作業繳交截止日:9/7(日) 完課證書發送時間:9/26(五)前 影音觀看期限:直播錄影將為您保留半年,期限為 2026/03/31

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully