Bird
Raised Fist0
Vueframework~5 mins

Pages and file-based routing in Vue - Cheat Sheet & Quick Revision

Choose your learning style10 modes available
Recall & Review
beginner
What is file-based routing in Vue?
File-based routing means the app creates routes automatically based on the files in the pages folder. Each file becomes a page with its own URL.
Click to reveal answer
beginner
How does Vue determine the URL path from a file name in file-based routing?
Vue uses the file name and folder structure to build the URL path. For example, a file named about.vue becomes /about in the URL.
Click to reveal answer
intermediate
How do you create a nested route using file-based routing in Vue?
You create a folder inside the pages folder and put Vue files inside it. The folder name becomes part of the URL path, making nested routes.
Click to reveal answer
intermediate
What special file name is used to create a dynamic route in Vue file-based routing?
You use square brackets around the file name, like [id].vue. This means the route can accept different values for id.
Click to reveal answer
beginner
Why is file-based routing helpful for beginners?
It saves time because you don't write route code manually. You just add files and Vue handles the URLs. It also keeps the project organized.
Click to reveal answer
In Vue file-based routing, what URL does the file pages/contact.vue map to?
A/contact
B/pages/contact
C/contact.vue
D/
How do you create a dynamic route for user profiles in Vue file-based routing?
ACreate a file named <code>user.vue</code>
BCreate a folder named <code>user</code>
CCreate a file named <code>[user].vue</code>
DCreate a file named <code>user-profile.vue</code>
What happens if you create a folder blog inside pages and add post.vue inside it?
AURL becomes <code>/post</code>
BURL becomes <code>/blog/post</code>
CURL becomes <code>/pages/blog/post</code>
DNo route is created
Which file name creates the home page route / in Vue file-based routing?
Aindex.vue
Bmain.vue
Chome.vue
Droot.vue
What is a benefit of using file-based routing in Vue?
AIt disables dynamic routing
BYou must write all routes manually
CIt only works for small projects
DRoutes update automatically when you add or remove files
Explain how Vue uses file names and folders to create routes in file-based routing.
Think about how your folder and file structure looks like a website map.
You got /4 concepts.
    Describe how to create a dynamic user profile page route using Vue file-based routing.
    Dynamic routes use special file names to accept variables.
    You got /3 concepts.

      Practice

      (1/5)
      1. In Vue file-based routing, what does a file named about.vue inside the pages folder represent?
      easy
      A. A route accessible at /about
      B. A nested route under /pages
      C. A dynamic route capturing a parameter
      D. A global component, not a route

      Solution

      1. Step 1: Understand file-based routing basics

        Files inside the pages folder automatically become routes matching their file names.
      2. Step 2: Map file name to route path

        The file about.vue creates a route at /about directly.
      3. Final Answer:

        A route accessible at /about -> Option A
      4. Quick Check:

        File name = route path [OK]
      Hint: File name equals route path without extension [OK]
      Common Mistakes:
      • Thinking files create nested routes automatically
      • Confusing dynamic routes with static file names
      • Assuming files are just components, not routes
      2. Which of the following is the correct way to define a dynamic route for a user profile page capturing userId in Vue file-based routing?
      easy
      A. pages/user/[userId].vue
      B. pages/user/:userId.vue
      C. pages/user/_userId.vue
      D. pages/user/userId.vue

      Solution

      1. Step 1: Recall dynamic route syntax

        Vue file-based routing uses square brackets to define dynamic segments in file names.
      2. Step 2: Match syntax to options

        The correct syntax is [userId].vue inside the folder representing the route.
      3. Final Answer:

        pages/user/[userId].vue -> Option A
      4. Quick Check:

        Dynamic route uses [param] syntax [OK]
      Hint: Use square brackets for dynamic route params [OK]
      Common Mistakes:
      • Using colon syntax like in Vue Router config
      • Using underscore prefix which is invalid here
      • Naming file literally as param name without brackets
      3. Given the following folder structure inside pages:
      pages/
        blog/
          [slug].vue
        index.vue

      What URL path will render the component in blog/[slug].vue when visiting /blog/vue-routing?
      medium
      A. The component renders but slug is undefined
      B. The component receives slug = 'vue-routing' as a route param
      C. The URL /blog/vue-routing does not match any route
      D. The component renders but with slug = 'blog/vue-routing'

      Solution

      1. Step 1: Identify dynamic route usage

        The file [slug].vue inside blog folder captures the segment after /blog/ as slug.
      2. Step 2: Match URL to route param

        Visiting /blog/vue-routing sets slug to 'vue-routing' for the component.
      3. Final Answer:

        The component receives slug = 'vue-routing' as a route param -> Option B
      4. Quick Check:

        Dynamic segment captures URL part [OK]
      Hint: Dynamic file name captures URL segment as param [OK]
      Common Mistakes:
      • Assuming slug is undefined without explicit props
      • Thinking URL must exactly match file name
      • Confusing nested folder names with param values
      4. You have a file pages/blog/[postId].vue but visiting /blog/123 shows a 404 error. What is the most likely cause?
      medium
      A. The route parameter is not passed as a prop to the component
      B. The file name should be _postId.vue instead of using brackets
      C. The pages folder is missing or misnamed
      D. The dynamic route file is inside the wrong folder

      Solution

      1. Step 1: Check folder structure

        For file-based routing to work, the pages folder must exist at the correct location.
      2. Step 2: Understand 404 cause

        If pages folder is missing or misnamed, routes won't be generated, causing 404 errors.
      3. Final Answer:

        The pages folder is missing or misnamed -> Option C
      4. Quick Check:

        Missing pages folder causes no routes [OK]
      Hint: Check if pages folder exists and is correctly named [OK]
      Common Mistakes:
      • Confusing dynamic file syntax with underscore prefix
      • Assuming props passing affects route matching
      • Placing dynamic file in wrong folder without realizing
      5. You want to create nested routes for a blog with categories and posts, where URLs look like /blog/tech/vue-routing. Which folder and file structure inside pages correctly sets this up?
      hard
      A. pages/blog/category/post.vue
      B. pages/blog/[category-post].vue
      C. pages/blog/[category]/post.vue
      D. pages/blog/[category]/[post].vue

      Solution

      1. Step 1: Understand nested dynamic routes

        Nested folders represent URL segments; dynamic segments use square brackets for variables.
      2. Step 2: Match URL pattern to folder structure

        The URL /blog/tech/vue-routing has two dynamic parts after /blog: category and post.
      3. Step 3: Verify correct file path

        Using pages/blog/[category]/[post].vue matches the URL segments correctly.
      4. Final Answer:

        pages/blog/[category]/[post].vue -> Option D
      5. Quick Check:

        Nested folders with [param] files match nested dynamic routes [OK]
      Hint: Use nested folders with bracketed files for nested dynamic routes [OK]
      Common Mistakes:
      • Combining params in one file name incorrectly
      • Using static folder names for dynamic segments
      • Misplacing files causing route mismatches
      Recommended

      Ready to prove it?

      Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

      10 questions~5 mineasy hard