Coder Social home page Coder Social logo

Comments (2)

christopherthielen avatar christopherthielen commented on April 23, 2024

With @uirouter/react (not react-hybrid), the router is added to the react context using the UIRouter react component. With react-hybrid, the router is automatically added to the react context when you route to a react component.

This error may show up when you're routing to AngularJS, using react2angular inside the angular component, and trying to use a @uirouter/react component such as UIView or UISref. To work around this issue, you can manually add the router to the react context for any react2angular components that use things like UISref.

Using UIRouterContextComponent

In your react2angular component that uses UISref, wrap in <UIRouterContextComponent>:

const MyComponent = () => (
  <UIRouterContextComponent>
    <div>
      <UISref to="mystate">
        <a>mystate</a>
      </UISref>
    </div>
  </UIRouterContextComponent>
)

angular.component('myComponent', react2angular(MyComponent));

Using UIRouterContext decorator

If you are using decorators (typescript or babel), you can decorate your class component:

@UIRouterContext
class MyComponent extends React.Component (
  render() {
    return (
    <div>
      <UISref to="mystate">
        <a>mystate</a>
      </UISref>
    </div>
    )
  }
}

angular.component('myComponent', react2angular(MyComponent));

from react-hybrid.

iNishant avatar iNishant commented on April 23, 2024

This works. Thanks. Missed this part of the Readme: https://github.com/ui-router/react-hybrid#providing-context-to-children .

from react-hybrid.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.