单击并显示默认页面后,反应重定向到路由器URL

时间:2016-01-27 12:34:36

标签: javascript reactjs react-router redux

我有一个public class PushNotificationReceiver extends ParsePushBroadcastReceiver implements LocationListener{ @Override public void onPushReceive(Context context, Intent intent) { //WakeLock pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); wakeLock = pm.newWakeLock((pm.SCREEN_BRIGHT_WAKE_LOCK | pm.FULL_WAKE_LOCK | pm.ACQUIRE_CAUSES_WAKEUP), "TAG"); wakeLock.acquire(); JSONObject pushData; String alert = null; String title = null; try { pushData = new JSONObject(intent.getStringExtra(PushNotificationReceiver.KEY_PUSH_DATA)); alert = pushData.getString("alert"); title = pushData.getString("title"); } catch (JSONException e) {} LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); //Getting LOCATION getLocation(context, locationManager); Intent cIntent = new Intent(PushNotificationReceiver.ACTION_PUSH_OPEN); cIntent.putExtras(intent.getExtras()); cIntent.setPackage(context.getPackageName()); PendingIntent pContentIntent = PendingIntent.getBroadcast(context, 0 /*just for testing*/, cIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder .setSmallIcon(R.drawable.car190) .setContentTitle(alert) .setContentText(title) .setContentIntent(pContentIntent) .setAutoCancel(true); NotificationManager myNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); myNotificationManager.notify(1, builder.build()); } private void getLocation(final Context context, final LocationManager locationManager){ locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this); locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this); //Stop receiving LOCATION after 5 sec final Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { locationManager.removeUpdates(PushNotificationReceiver.this); //WakeLock release wakeLock.release(); } }, 5000); } @Override public void onLocationChanged(Location location) { currentLat = location.getLatitude() + ""; currentLng = location.getLongitude() + ""; currentDate = new Date(); String username = tabFragment1.usernameResponse; try { JSONObject object = new JSONObject(username); myusername = object.getString("ID"); } catch (JSONException e) { e.printStackTrace(); } //POST to Database postLocation(mainActivity.getAppContext(), currentLat, currentLng, currentDate.toString(), myusername); } } 组件,如:

Header

和我的class Header extends Component { render() { return ( <div> <h3><Link to="/:one">One</Link></h3> <h3><Link to="/:two">Two</Link></h3> </div> ) } } export default Header

App.js

我的目的是像导航栏一样显示标题..

我有路由器,如:

class App extends Component {
  render() {
    return (
      <div>
        <Header />
      </div>
    )
  }
}
export default App

当我点击const routes = ( <Route path="/" component={App}> <Route path="/:login" component={Login} /> <Route path="/:one" component={One} /> <Route path="/:two" component={Two} /> </Route> ) export default routes Header时,我的One会在该页面中重定向。

我想要的主要是我希望每个页面都有Two个组件..就像导航栏一样..

在我的Header我只有App.js组件。当我在浏览器中转到Header时,它应显示/页面为默认值。

我需要指南来完成这个..

我很反应

提前致谢..

1 个答案:

答案 0 :(得分:0)

1。 {this.props.children}添加App.js,如下所示:

class App extends Component {
  render() {
    return ( 
        <div>
            <Header />
            {this.props.children}
        </div>
    )
  }
}
export default App

并更改路线文件

const routes =  (
  <Route path="/" component={App}>
        <Route path="/login" component={Login} />
        <Route path="/one" component={One} />
        <Route path="/two" component={Two} />
  </Route>
)
export default routes

一直显示标题,如navbar。

<强> 2 简单的身份验证示例

react-router auth example