GVKun编程网logo

动作重做后反应路由器重定向(路由重定向的过程)

11

在本文中,我们将详细介绍动作重做后反应路由器重定向的各个方面,并为您提供关于路由重定向的过程的相关解答,同时,我们也将为您带来关于AngularJS简单文件下载导致路由器重定向、javascript–

在本文中,我们将详细介绍动作重做后反应路由器重定向的各个方面,并为您提供关于路由重定向的过程的相关解答,同时,我们也将为您带来关于AngularJS简单文件下载导致路由器重定向、javascript – 反应路由器 – 路由到子组件的路径、React js:反应路由器不重定向、react-router – 错误刷新路由器反应路由器的有用知识。

本文目录一览:

动作重做后反应路由器重定向(路由重定向的过程)

动作重做后反应路由器重定向(路由重定向的过程)

我正在使用react-redux和标准react-routing。确定动作后,我需要重定向。

例如:我已经注册了几个步骤。并采取以下措施:

function registerStep1Success(object) {    return {        type: REGISTER_STEP1_SUCCESS,        status: object.status   };}

我希望他重定向到带有registrationStep2的页面。怎么做?

ps在历史浏览器中从未使用过“ / registrationStep2”。仅在成功注册结果步骤1页面之后,才会显示此页面。

答案1

小编典典

使用React Router
2+,无论您在何处调度操作,都可以调用browserHistory.push()(或者hashHistory.push()如果使用的话):

import { browserHistory } from ''react-router''// ...this.props.dispatch(registerStep1Success())browserHistory.push(''/registrationStep2'')

您也可以从异步操作创建者处执行此操作。

AngularJS简单文件下载导致路由器重定向

AngularJS简单文件下载导致路由器重定向

HTML:

<a href="mysite.com/uploads/asd4a4d5a.pdf" download="foo.pdf">

当数据库中保留真实姓名时,上传将获得唯一的文件名。我想实现一个简单的文件下载。但由于以下原因,上面的代码重定向到/:

$routeProvider.otherwise({
    redirectTo: '/',controller: MainController
});

我尝试过

$scope.download = function(resource){
    window.open(resource);
}

但这只是在新窗口中打开文件。

有什么想法如何为任何文件类型启用真正的下载吗?

javascript – 反应路由器 – 路由到子组件的路径

javascript – 反应路由器 – 路由到子组件的路径

有人可以告诉我最好的办法吗?我想从我的路线传递一个页面标题道具到我的标题子组件.这是我的路线:
var sampleApp= React.createClass({

render: function (){
    return (
        <div className="our-schools-app">
            <Header />
            <RouteHandler />
            <Footer />
        </div>
    );
},});

var routes = (
<Route name="app" path="/" handler={OurSchoolsApp}>
    <DefaultRoute name="home" handler={HomePage}  />
    <Route name="add-school" handler={AddSchoolPage}  />
    <Route name="calendar" handler={CalendarPage}  />
    <Route name="calendar-detail" path="calendar-detail/:id" handler={CalendarDetailPage} />
    <Route name="info-detail" path="info-detail/:id" handler={InfoDetailPage} />
    <Route name="info" handler={InfoPage} />
    <Route name="news" handler={NewsListPage} />
    <Route name="news-detail" path="news-detail/:id" handler={NewsDetailPage} />
    <Route name="contacts" handler={ContactPage} />
    <Route name="contact-detail" handler={ContactDetailPage} />
    <Route name="settings" handler={SettingsPage} />
</Route>
);


Router.run(routes,function(Handler){
var mountNode = document.getElementById('app');
React.render(<Handler />,mountNode);
});

我想在路线中传递我的页面的标题作为支柱,如下所示:

<Route name="info" handler={InfoPage} pageTitle="Info Page" />

对我的标题组件:

var Header = React.createClass({

render: function () {
    return (
            <div className="bar bar-header"
                style={this.getStyle()}>
                 <HomeButton />
                 <div className="h1 title">{this.props.pageTitle}</div>
            </div>
    )
}
});

但道具显示为空,有人可以帮忙吗?

解决方法

目前您无法使用React Router(1.0)进行此操作.我相信一个推荐的方法是包装纸组件:
var BaseComponent = React.createClass({
     render: function() {
        return <p>{this.props.text}</p>
     }
});

var FancyComponent = React.createClass({
     return <BaseComponent text="fancy!" />
});

var EvenFancierComponent = React.createClass({
     return <BaseComponent text="SUPER fancy!" />
});

那么这些路线:

<Route name="standard" handler={BaseComponent} />
<Route name="fancy" handler={FancyComponent} />
<Route name="superfancy" handler={EvenFancierComponent} />

不过关于React Router github issues这个话题的讨论提供了一个好消息:

I just wanted to note here that in the new API (see 07001) routes are
just plain objects,so you can put whatever props you want on them.
Your transition hooks will get a route arg and components will receive
this.props.route,so you should be good to go.

它看起来像是新的1.0版本是beta版,所以应该很快来了!

React js:反应路由器不重定向

React js:反应路由器不重定向

我建议使用历史记录以编程方式导航到搜索。您可能希望将 inputVal 作为查询参数传递,以便您可以在该组件中访问它。

import { useHistory } from 'react-router-dom';

function App() {
    const history = useHistory();
    const [inputVal,setInputVal] = useState('');

    function handleInput(e) {
        const query = e.target.value;
        setInputVal(query);
    }

    function handleKeyDown(e) {
        if (e.key === 'Enter') {
            // You can put the inputVal as a query parameter
            history.push(`/search?search=${inputVal}`);
        }
    }

    return (
        <div className="App">
            <div>
                <h1>Movie</h1>
                <input
                    onKeyDown={handleKeyDown}
                    onChange={handleInput}
                    placeholder="Search..."
                />
            </div>

            <Router>
                <Switch>
                    <Route path="/" exact component={Home} />
                    <Route path="/search" component={Search} />
                    <Route path="/details/:id" component={Detail} />
                </Switch>
            </Router>
        </div>
    );
}
,

它总是在你的 switch 中选择第一个,所以因为你在主页上,它可能永远不会看到下面的任何东西,这就是为什么它不会重定向你。您要么需要将重定向放在主路由上方,要么尝试使用 react-router 中的“历史记录”功能,这将要求您在根级别进行设置才能使用,但您可以这样做

function handleKeyDown(e) {
    if (e.key === 'Enter') {
        history.push('/search')
        console.log(submitted);
        console.log(inputVal);
    }
}

react-router – 错误刷新路由器反应路由器

react-router – 错误刷新路由器反应路由器

当我点击包含url products / new的链接时,我可以访问新的产品页面并且它工作正常,但是如果我刷新页面它会返回Uncaught SyntaxError:Unexpected token<. 我该如何解决这个问题? 页面产品新
import React from 'react';

class ProductNew extends React.Component {
  constructor(props) {
    super(props);
  }
  render(){
    return (
      <div>
        <div><h1>ProductNew</h1></div>
      </div>
    );
  }
}

module.exports = ProductNew;

页面产品

import React from 'react';
import { Link }  from 'react-router';

class Products extends React.Component {
  constructor(props) {
    super(props);
  }
  render() {
    return (
      <div>
        <div><h1>Products</h1></div>
        <Link to="/products/new">new</Link>
      </div>
    );
  }
}

module.exports = Products;

页面应用程序

render((
  <Router history={createbrowserHistory()}>
    <Route path="/" component={Layout}>
       <IndexRoute component={Home} />
       <Route path="/products" component={Products}/>
       <Route path="/products/new" component={ProductNew}/>
    </Route>
  </Router>
),document.getElementById('app'));
我遇到了类似的问题,我的App.js路径是相对的.
因此,当我从主路径加载应用程序页面时,一切运行良好,但当我尝试从您的“/ product / new”链接加载时,我收到了类似您的错误.当我放一条绝对路径时,它工作得很好.

我使用webpack捆绑文件和webpack-dev-server来运行开发环境,当你使用webpack-dev-server热加载器(默认情况下)时没有物理文件,这很容易陷入困境.

编辑:
this guy’s question有2个更新,与你有同样的问题,并有比我给你更好的答案/信息.

今天关于动作重做后反应路由器重定向路由重定向的过程的讲解已经结束,谢谢您的阅读,如果想了解更多关于AngularJS简单文件下载导致路由器重定向、javascript – 反应路由器 – 路由到子组件的路径、React js:反应路由器不重定向、react-router – 错误刷新路由器反应路由器的相关知识,请在本站搜索。

本文标签: