意外的浏览器历史行为(Meteor + React + React Router)

时间:2016-06-30 06:17:35

标签: meteor react-router

(PS:我正在使用Meteor + React + React Router。应用程序结构不是传统的,我正在创建一个package-esq应用程序,例如https://github.com/TelescopeJS/Telescope。我正在尝试做动态使用反应路由器进行路由并且事情进展顺利。)

browserHistory有问题。导航刷新页面。通过浏览器按钮来回刷新页面。

所有代码的示例都在这里 - https://github.com/dbx834/sandbox

特定于React-Router的代码,

在具有全局导出的核心包中,允许注册路由和组件

...
// ------------------------------------- Components -------------------------------- //

Sandbox.components = {};

Sandbox.registerComponent = (name, component) => {
  Sandbox.components[name] = component;
};

Sandbox.getComponent = (name) => {
  return Sandbox.components[name];
};

// ------------------------------------- Routes -------------------------------- //

Sandbox.routes = {};
Sandbox.routes.routes = [];

Sandbox.routes = {
  routes: [],
  add(routeOrRouteArray) {
    const addedRoutes = Array.isArray(routeOrRouteArray) ? routeOrRouteArray : [routeOrRouteArray];
    this.routes = this.routes.concat(addedRoutes);
  },
};
...

在各种实现中(特定于域的逻辑,UI等),注册组件和路由

...
import TodoApp from './components/TodoApp.jsx';

Sandbox.registerComponent('TodoApp', TodoApp);

Sandbox.routes.add([
  { name: 'todoAppRoute', path: 'todo-app', component: Sandbox.components.TodoApp },
]);
...

在主应用中

import React from 'react';
import { render } from 'react-dom';
import { Meteor } from 'meteor/meteor';
import { Router, browserHistory } from 'react-router';

import App from './components/App.jsx';
import Homepage from './components/Homepage.jsx';

Sandbox.registerComponent('App', App);
Sandbox.registerComponent('Homepage', Homepage);

Meteor.startup(() => {

  const AppRoutes = {
    path: '/',
    component: Sandbox.components.App,
    indexRoute: { name: 'home', component: Sandbox.components.Homepage },
    childRoutes: Sandbox.routes.routes,
  };

  console.log(AppRoutes);

  render(
    <Router routes={AppRoutes} history={browserHistory} />,
    document.getElementById('app-root')
  );
});

有什么问题?

1 个答案:

答案 0 :(得分:0)

我卸载了所有npm软件包,meteor软件包,更新了所有内容,重新安装了最新的软件包,清理了所有以前的版本,现在一切正常!

某处有些奇怪。

如果有人发现自己处于类似情况,你可以试试这个。

最佳

相关问题