Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React with Adonis

I am trying to integrate React with Adonis Js to build an SPA. Adonis handles routing to an SPA by

Route.any('*', function * (request, response) {
 yield response.sendView('home')
})

I have done exactly that in app > Http > routes.js

Then I created a home.njk in resources > views to act as the landing page for my application. Now, I have a react file where I have created a footer. I want to handle all the links in the footer with React-router. React router handles urls to navigate to a page. However, the above code(in Adonis) says that any url (*) is going to render 'home'. That is exactly what is happening.

How do get around it? Thanks!

like image 682
Roy Avatar asked Nov 16 '16 08:11

Roy


1 Answers

You should define your api routes before the route *.

Adonis Router will go through your routes.js file and get the first route that match.

like image 112
Romain Lanz Avatar answered Sep 21 '22 07:09

Romain Lanz