Angular and ui-router state children
Date : March 29 2020, 07:55 AM
will be helpful for those in need I got this working today. My sport state stayed the same. I changed the designer states to this: // Set up our state(s)
$stateProvider.state('designer', {
url: ':sport/designer',
abstract: true,
templateUrl: '/app/designer/designer.tpl.html',
controller: 'DesignerController',
controllerAs: 'controller'
}).state('designer.team', {
url: '',
templateUrl: '/app/designer/team.tpl.html'
}).state('designer.kit', {
url: '/kit',
templateUrl: '/app/designer/kit.tpl.html'
}).state('designer.design', {
url: '/design',
templateUrl: '/app/designer/design.tpl.html'
}).state('designer.refine', {
url: '/refine',
templateUrl: '/app/designer/refine.tpl.html'
}).state('designer.order', {
url: '/order',
templateUrl: '/app/designer/order.tpl.html'
});
<div class="container">
<div class="row">
<div class="col-md-12">
<h1>{{ controler.slug }}</h1>
<p>This will be the sport homepage.</p>
<p><a ui-sref="designer.team({ sport: controller.slug })">Click to get started</a></p>
</div>
</div>
</div>
|
React router and this.props.children - how to pass state to this.props.children
Date : March 29 2020, 07:55 AM
hope this fix your issue This question boils down to, how do you pass props to children? June 2018 answer import React from 'react'
import { BrowserRouter, Route } from 'react-router-dom'
// some component you made
import Title from './Title'
class App extends React.Component {
// this.state
state = { title: 'foo' }
// this.render
render() {
return (
<BrowserRouter>
// when the url is `/test` run this Route's render function:
<Route path="/:foobar" render={
// argument is props passed from `<Route /`>
routeProps =>
// render Title component
<Title
// pass this.state values
title={this.state.title}
// pass routeProps values (url stuff)
page={routeProps.match.params.foobar} // "test"
/>
} />
</BrowserRouter>
)
}
}
// "smart" component aka "container"
class App extends React.Component {
state = { foo: 'bar' }
render() {
return this.props.children(this.state.foo)
}
}
// "dumb" component aka "presentational"
const Title = () => (
<App>
{title => <h1>{title}</h1>}
</App>
)
render: function() {
var children = React.Children.map(this.props.children, function (child) {
return React.cloneElement(child, {
foo: this.state.foo
})
})
return <div>{children}</div>
}
|
React router update parent state from children class
Date : March 29 2020, 07:55 AM
wish helps you Suppose my routes as below: , To make this work, you could end up with something like this: var Base = React.createClass({
getInitialState() {
return {current: 1}
},
render() {
return (
<div>{this.state.current}</div>
<div>{this.props.children}</div>
<div>{this.props.demo}</div>
);
}
});
export default connect(state => ({
demo: state.demo
}))(Base);
---
var A = React.createClass({
componentDidMount() {
// how to set base class state
//
this.props.setDemo('demo');
},
render() {
....
}
});
export default connect(() => ({}), {
setDemo
});
|
Angular UI Router - Prevent re-running of parent state when switching between children
Date : March 29 2020, 07:55 AM
help you fix your problem The cause of this actually turned out to be higher up in the state hierarchy. Between each state transition an ACL permissions check was taking place, and during this process a $rootScope variable was being set to false during the check, then updated to true once resolved. The main application container had a ng-if="$root.userIsAuthorised" which removed the entire app from the DOM, then re-added it. This caused all of the routing to re-run and in turn the controllers to re run. In short, the fix was to use ng-show / ng-hide to handle hiding without removing from the DOM and the controllers ran as expected.
|
Angular 6 UI Router class resolvers
Date : March 29 2020, 07:55 AM
wish helps you FYI UI-Router for Angular (@uirouter/angular) is a totally separate implementation -- it does not extend the Angular Router (@angular/router). The resolve system in @uirouter/angular works much the same as the resolve system of the AngularJS version. The main difference is that services in AngularJS must always be injected using a string token. In Angular, services may be injected using Token objects (OpaqueToken or InjectionToken) or class references. export const pageDataResolver = ($transition$) => {
const _page: PageService = $transition$.injector().get(PageService);
const ngRedux: NgRedux<IAppState> = $transition$.injector().get(NgRedux);
return this._page.getPageInformation(
this.ngRedux.getState().currentLanguage,
route.paramMap.get('slug')
).toPromise();
}
const routes = {
states: [{
name: 'page',
url: '/page/:slug/',
component: ViewPageComponent,
resolve: {
boatData: PageDataResolver
},
parent: 'public'
}]
};
|