Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Follow Link option fails when using custom Inertia resolve path #137

Open
m4rinos opened this issue Dec 27, 2024 · 0 comments
Open
Assignees
Labels

Comments

@m4rinos
Copy link

m4rinos commented Dec 27, 2024

Extension Version

0.1.14

PHP Binary

Docker

Operating System

macOS

What happened?

In locations where follow link is implemented (i.e. in the web.php routes file) the plugin displays an error stating it cannot find the location of the Inertia view when it is custom, so all inertia pages that are not located within js/Pages directory.

Screenshot 2024-12-27 at 19 21 48

Mimimal Code Sample

import { resolvePageComponent } from 'laravel-vite-plugin/inertia-helpers';

/**
 * Mapping project prefixes to their predefined glob patterns.
 */
const projectMap = {
    'Base': import.meta.glob('./Base/Pages/**/*.vue'),
    'Blog': import.meta.glob('./Blog/Pages/**/*.vue'),
    'Default': import.meta.glob('../Pages/**/*.vue'),
};

/**
 * Custom resolve logic for Inertia pages using a map for efficiency.
 */
export function resolvePage(name) {
    // Determine the glob object based on the prefix in the name
    const [prefix] = name.split('/'); // Get the first segment of the name (e.g., 'Base')
    const glob = projectMap[prefix] || projectMap['Default']; // Use the matching glob or default glob

    // Resolve the page component
    return resolvePageComponent(`./${name}.vue`, glob)
        .then((resolved) => resolved);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants