最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - React with Adonis - Stack Overflow

programmeradmin5浏览0评论

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!

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!

Share Improve this question asked Nov 16, 2016 at 8:48 RoyRoy 3691 gold badge4 silver badges11 bronze badges 2
  • Mind sharing some code? – Aman Virk Commented Nov 18, 2016 at 10:39
  • There is not much code to share actually. I appreciate your interest though. This is my first project in node.js and I choose Adonis. So I;ll be needing your assistance a lot. Thanks! – Roy Commented Nov 18, 2016 at 12:58
Add a ment  | 

1 Answer 1

Reset to default 9

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.

发布评论

评论列表(0)

  1. 暂无评论