1

I want to structure my router.js file as currently there is around 500 lines of code in it.

{
            path: "/",
            component: () => import("./../src/views/dashboard/Dashboard.vue"),
            meta: {
                auth: true,
                title: "Dashboard"
            }
        },
        {
            path: "/regionWiseDashboard",
            component: () => import("./../src/views/dashboard/RegionWiseDashboard.vue"),
            meta: {
                auth: true,
                title: "Dashboard"
            }
        },

The above code is repeating for every component I include in my project which just makes the code look more and more unreadable. Can I structure it anyhow? Maybe put all files in an JSON or divide the main js file into children js files?

3
  • an JSON object - no such thing ... did you mean JSON or an object? Commented Jan 18, 2020 at 7:59
  • @JaromandaX that was a typing error. Sorry for that. Your comment would have been of more help if you would have answered my question though. Commented Jan 18, 2020 at 8:09
  • your question is, "maybe put all the files in a JSON" - this makes no sense, how does one put files into JSON? so I can't answer that. "or divide the main js file into children js files" - this again makes no sense since your problem is with a single object you are passing to create the router Commented Jan 18, 2020 at 8:14

1 Answer 1

3

How I structured my routes in vue.

First: create a folder named routes, inside this folder, create subfolders depends on how you group your routes. Example, villages, dashboard, user

Second: create a main route inside your routes folder. This main route will hold and import all your routes made in villages, dashboard, user.

last: import this main route to your main app.js

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.