karlhepler / angular-middleware Goto Github PK
View Code? Open in Web Editor NEWLaravel-like middleware for Angular ui.router and ngRoute
License: MIT License
Laravel-like middleware for Angular ui.router and ngRoute
License: MIT License
The repo on npm is out of date.
The redirectTo function in src/middleware.factory.js
doesn't have params
and options
parameters. When install via npm the function has only route
parameter available.
/**
* Redirect to another route
*
* @returns {void}
*/
function redirectTo(route, params, options) {
middleware.resolution.reject({
type: "redirectTo",
route: route,
params: params,
options: options
});
}
Love this new middleware. After coding a new NodeJS backend it got me thinking that really Angular needed middleware too ... and here it is ๐ . I'd propose it be part of Angular core.
What I think the documentation lacks is ...
Adding these powerful examples should really help sell your concept.
Any plans to support ui-router 1.0 ? They've moved away from the $stateChange* events in favor of transition hooks: https://github.com/angular-ui/ui-router/releases/tag/1.0.0alpha0
I'm going to try and fork the repo and add support for it
When I include the module, all of my states stop rendering their templates. There are no errors in the console either.
angular.module('app.core', ['ngCookies', 'ui.router', 'ui.router.middleware']);
Hey!
Have you reached a verdict with Angular2 implementation of middlewares?
thanks
In the ngRoute test file, the global middleware gets called twice in a row when initialized. Not sure why, but ui.router doesn't have this behavior. The ui.router configuration calls it once, as it should.
Hi,
I always get those error when setup the middleware. here is my code:
$middlewareProvider.map({
'check-token': ['Auth', (Auth) => {
const request = this;
Auth.get({ url: 'check-token' }, response => {
if (response) {
return request.next();
}
});
}]
});
One might want to set up a state to redirect to a sub-state using middleware.
Say, /docs
always redirects to /docs/getting-started
.
When a simple this.redirectTo('parent.child')
middleware is written and called when routing to the parent
state, it results in an infinite loop.
Example: (caution: crashes page)
https://plnkr.co/edit/syZdLJQ2I8ZomP7T9ndA?p=preview
In this example, there are state one
with sub-states, one.one
and one.two
and state two
. Presently, the only middleware used is one that simply calls this.next()
.
If one changes the middleware at the two lines commented with // Change to 'redirect' middleware
to the redirect
middleware, one expects that clicking the one
and two
links redirect to sub-state one.one
. The two
link performs as expected, but clicking the one
link causes an infinite loop.
Hello,
Inside a middleware function, I tried to access 'this.route' and it gets undefined.
Tried this as saw in at the bottom of the documentation.
Thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.