Skip to content
This repository was archived by the owner on Feb 2, 2025. It is now read-only.
This repository was archived by the owner on Feb 2, 2025. It is now read-only.

Use custom router or symlinks to avoid code duplication #3

Description

@Kasheftin

That's a very interesting and useful article and the code!
I noticed that the pages/index.vue, pages/top.vue, and pages/t/_tag.vue use pretty much the same code. It's possible to use the route name or path to determine what has to be shown and avoid code duplication. There're several simple ways to refactor this:

  1. Move the pages/index.vue content to components/ArticleList.vue (and get an advantage of the new fetch approach being used in components one more time). Call it from index.vue like that:
<template>
  <article-list query="tag=nuxt&state=rising" title="New Nuxt.js articles" />
</template>
  1. Use pages/_page.vue as the default route handler and place article list there (but it will require to move authors to the /authors/_username route, and tags to /?tag=.. query).

  2. Write the custom router in the nuxt.config.js.

  3. Convert pages/index.vue, pages/top.vue and pages/t/_tag.vue to the symlinks that point to the same common_pages/index.vue file and parse the route there manually.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions