Uncaught Error: Ziggy error: route is not in the route list

2.4k views Asked by At

I have a Laravel project along with Inertia.js and React.js. It was running well in my development machine (aka localhost). But it has trouble when I deployed it to Apache server in a virtual private server

When I hit /login endpoint, it returns Uncaught Error: Ziggy error: route '/login' is not in the route list.

I already change the APP_URL in .env to the domain that I used. This is the dependencies that I used in my project

"dependencies": {
    "@draft-js-plugins/static-toolbar": "^4.1.2",
    "@fortawesome/fontawesome-free": "5.15.3",
    "@popperjs/core": "2.9.1",
    "@tailwindcss/forms": "0.2.1",
    "autoprefixer": "10.2.5",
    "babel-plugin-macros": "^3.1.0",
    "chart.js": "^3.9.1",
    "draft-js": "^0.11.7",
    "gulp": "4.0.2",
    "gulp-append-prepend": "1.0.8",
    "js-file-download": "^0.4.12",
    "moment": "^2.29.1",
    "numeral": "^2.0.6",
    "postcss": "8.2.8",
    "quill-image-resize-module-react": "^3.0.0",
    "react": "17.0.1",
    "react-alert": "^7.0.3",
    "react-alert-template-basic": "^1.0.2",
    "react-chartjs-2": "^4.3.1",
    "react-dom": "17.0.1",
    "react-google-recaptcha": "^2.1.0",
    "react-js-pagination": "^3.0.3",
    "react-moment": "^1.1.1",
    "react-pluralize": "^1.6.3",
    "react-quill": "^2.0.0-beta.4",
    "react-recaptcha": "^2.3.10",
    "react-router": "5.2.0",
    "react-router-dom": "5.2.0",
    "react-scripts": "4.0.3",
    "react-select": "^5.0.0",
    "slate": "^0.66.1",
    "slate-react": "^0.66.1"
}

This is the route file that I have related to the login endpoint

Auth::routes(['verify' => true]);

Route::middleware('guest')->group(function () {
    Route::get('/login', [AuthenticatedSessionController::class, 'create'])->name('login');
    Route::post('/login', [AuthenticatedSessionController::class, 'store'])->name('login');
});

This is how I invoke the login endpoint on react.js

const submit = (e) => {
    e.preventDefault();

    if(!data.CaptchaCode){
        alert('Invalid captcha!')
        return
    }

    post(route('/login'));

    recaptchaRef.current.reset();
}

In case it is needed, this is the Apache configuration in /etc/apache2/sites-available/laravel-project.conf

<VirtualHost *:80>
   ServerName mydomain.com
   ServerAdmin [email protected]
   DocumentRoot /var/www/project-folder/public

   <Directory /var/www/project-folder>
       AllowOverride All
       Require all granted
   </Directory>
   ErrorLog ${APACHE_LOG_DIR}/error.log
   CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Thank you for your help beforehand!

1

There are 1 answers

1
Joshua Fomubod On

With Ziggy, you need to pass the route name in the route('') not the route path.

Also, you have 2 routes with the same name in our route file.

const submit = (e) => {
 e.preventDefault();

 if(!data.CaptchaCode){
  alert('Invalid captcha!')
    return
 }

 post(route('/login')); //post(route('login'));

 recaptchaRef.current.reset();
}