0
我有以下途徑:重定向路線編程方式使用路線名稱
ReactDOM.render(
React.createElement(ReactRouter.Router, {history: ReactRouter.hashHistory},
React.createElement(ReactRouter.Route, {path: '/', component: AppController}),
React.createElement(ReactRouter.Route, {component: LayoutController},
React.createElement(ReactRouter.Route, {path: '/dashboard', component: DashboardController}),
React.createElement(ReactRouter.Route, {path: '/signout', component: UserSignoutController})
)
)
, document.getElementById('content'));
這是我的重定向應用程序流:
ReactRouter.browserHistory.push('/dashboard');
它的工作原理,但如果我打開我的應用程序上的另一機器具有不同的網址結構,並且我必須更改網址路徑,我也必須更改每個push
參數。
有沒有辦法使用路由名稱而不是路徑重定向?
我不明白這樣的路徑在另一臺機器上會有什麼不同。如果是這種情況,您是否還必須在路線中配置不同的路徑?順便說一句,這可能不是配置路線的理想方式。如果你不想用JSX來做,我會建議使用['PlainRoute'](https://github.com/reactjs/react-router/blob/69b163255ca6fc363fe270911b1161378650cc1b/docs/API.md#plainroute)對象寫出'React.createElement()'調用。 – JMM