veliovgroup / Meteor-flow-router-meta

Reactive meta tags, JavaScript links and CSS for meteor within flow-router-extra
https://packosphere.com/ostrio/flow-router-meta
BSD 3-Clause "New" or "Revised" License
38 stars 3 forks source link

Dynamic imports #13

Closed jasongrishkoff closed 4 years ago

jasongrishkoff commented 4 years ago

Hi there, I've got one big router.js file that has a whole bunch of routes inside it. For example:

FlowRouter.route('/', {
    name: 'home',
    async action(params, queryParams) {
        const { default: Layout } = await import('/imports/client/layout')
        const {
            default: Home,
        } = await import('/imports/client/home')
        mount(Layout, {
            content: <Home tab='home' page={Number(queryParams.page)} />
        })
    }
})

I've now got 100+ such routes in this file -- many of which are only relevant for certain users (such as an admin). Is there a way to dynamically import that route, but ONLY if the user is an admin? It's easy enough to dynamically import a file containing all the admin routes, but unless I do that as part of the main package, the admin page I'm trying to visit will result in a 404.

Appreciate any guidance!

J

jasongrishkoff commented 4 years ago

Sorry, this should be in the flow-router-extra repository.