0

I'm currently having a problem in my routing. Here's the scenario:

Inertia is working fine when there's no id query.

enter image description here

But after navigating to edit and I want to click any of the navigation links like clicking the Dashboard link, it throws a 404 code saying the page does not exist. Simply because instead of removing the /category/{id}, it adds dashboard at the end instead of removing the query.

enter image description here

Is there a way to fix this by not violating the inertia routing?

Here's the code:

Authenticated Layout

const navigation = [
  { name: 'Dashboard', href: 'dashboard', current: false },
  { name: 'Category', href: 'category', current: false },
  ]

 <nav class="hidden lg:flex lg:space-x-8 lg:py-2" aria-label="Global">
        <Link v-for="item in navigation" :key="item.name" 
        :href="item.href" :class="[item.current ? 'bg-gray-100 
         text-gray-900' : 'text-gray-900 hover:bg-gray-50 
         hover:text-gray-900', 'rounded-md py-2 px-3 inline-flex 
         items-center text-sm font-medium']" :aria- 
         current="item.current ? 'page' : undefined">{{ item.name 
         }}</Link>
 </nav>
1
  • try href="route('dashboard')" -- but i don't think it works. Commented Sep 17, 2022 at 15:30

2 Answers 2

0

Solved it. Just needed to add "/" to the href navigation object.

const navigation = [
   { name: 'Dashboard', href: '/dashboard', current: false },
   { name: 'Category', href: '/category', current: false },
]
Sign up to request clarification or add additional context in comments.

1 Comment

Despite the question title and tags, you're not actually using Ziggy at all, which is why you've had this trouble.
0

Have you tried using Ziggy? Ziggy Github repo

Then the routes you create using Laravel are made available using the same route function in Vue. It works well with inertia when creating laravel apps.

    <Link
       :href="route('frontend.categories.show', [categories, post.slug])"
    >

If you check your console in the page inspector it should show you the ziggy routes pulled from the "web.php" in json format.

It automatically makes the standard Controller class functions available for your routes in javascript (so index, create, edit, show, destroy functions).

I would be happy to share my code I created from a tutorial utilising breeze like you are.

2 Comments

I was gonna downvote you because Ziggy is in the title and the tags list, but OP isn't using Ziggy in any of their code. Good catch, +1 from me.
Thanks I could have been more clear in my answer.

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.