ng-redux-route
v1.0.5
Published
Redux middleware for use with Angular Route
Downloads
6
Readme
ng-redux-route
Usage:
import angular from 'angular';
import ngRoute from 'angular-route';
import { combineReducers } from 'redux';
import ngRedux from 'ng-redux';
import createLogger from 'redux-logger';
import ngReduxRoute, { routeActions, routeReducer } from 'ng-redux-route';
const rootReducer = combineReducers({
//app: appReducer
router: routeReducer,
});
const app = angular.module('app', [
ngRoute,
ngRedux,
ngReduxRoute,
])
.config(($ngReduxProvider) => {
const logger = createLogger({
level: 'info',
collapsed: true,
});
$ngReduxProvider.createStoreWith(rootReducer, ['ngRouteMiddleware', logger]);
})
.run(($ngRedux) => {
})
.name;
export default app;
setLocation(setters)
$ngRedux.dispatch(routeActions.setLocation([
{ fn: 'search', args: ['company', 1] }, // $location.search('company', 1)
{ fn: 'replace' }, // $location.replace()
])));
const mapStateToThis = state => ({
router: state.router,
});
const mapDispatchToThis = ({
setLocation: routeActions.setLocation,
});
const unsubscribe = $ngRedux.connect(mapStateToThis, mapDispatchToThis)(this);
$scope.$on('$destroy', unsubscribe);
this.setLocation([
{ fn: 'url', args: ['/some-url'] }, // $location.url('/some-url')
]);
Location Helpers
setUrl(url, [replace = false])
setPath(path, [replace = false])
setSearch(search, [paramValue, replace = false])
setHash(hash, [replace = false])
setState(state, [replace = false])
import { locationHelpers } from 'ng-redux-route';
locationHelpers.setUrl('/some-url', true)
// {
// type: '@@ngReduxRoute/setLocation',
// setters: [
// {fn: "url", args: ['/some-url']},
// {fn: "replace"},
// ]
// }