我正在開發一個使用Sails和React的Web應用程序。我使用sails的主要目的是利用MVC模式,而React用於服務視圖。因爲,Sails提供了自己的路由,但我想使用我的React-router。React + Sails:處理路線
例如:在react-router中我們有NotFoundRoute
,所以當我訪問一個不存在的頁面時,它應該顯示我爲NotFoundRoute
定義的處理程序。相反,它向我展示了風帆404頁面。
那麼如何在使用我的React路線時控制帆的路線?
陣營路線
var JSX = require('babel/register'),
React = require('react'),
Router = require('react-router'),
DefaultRoute = Router.DefaultRoute,
NotFoundRoute = Router.NotFoundRoute,
Route = Router.Route;
var routes = (
<Route name="splash" path="/" handler={require('../main')}>
<DefaultRoute handler={require('../components/Signup/signup')} />
<Route name="signup" path="/user/signup" handler={require('../components/Signup/signup')} />
<Route name="home" path="/user/home/:id" handler={require('../components/Home/home')} />
<NotFoundRoute handler={require('../components/commons/notFound')} />
</Route>
);
module.exports = routes;
帆路線
module.exports.routes = {
'/': {
view: 'homepage'
},
'/user/home/:id' : 'UserController.home'
};
我完全新的這個框架,並不能找到足夠的資源online..So對不起這個愚蠢的問題。
顯示您的Sails路由器代碼。可能的問題是,您沒有告訴Sails從您的React應用程序的index.html中提供所有**(通配符)請求。 – elithrar
@elithrar正如你所問,我已經添加了我的帆航線。請讓我知道..我需要做些什麼修改。 – Ricky
請參閱http://sailsjs.org/documentation/concepts/routes/custom-routes - 使用通配符路由 - '/ *' - * AFTER *您的'UserController'路由。 – elithrar