Coder Social home page Coder Social logo

karlhepler / angular-middleware Goto Github PK

View Code? Open in Web Editor NEW
33.0 3.0 4.0 54 KB

Laravel-like middleware for Angular ui.router and ngRoute

License: MIT License

JavaScript 90.79% HTML 9.21%
middleware ngroute router laravel angular angularjs ui-router

angular-middleware's People

Contributors

hjylewis avatar joshkoberstein avatar karlhepler avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

angular-middleware's Issues

[ui-router] Redirect to child view infinite loop

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.

Angular 2

Hey!
Have you reached a verdict with Angular2 implementation of middlewares?

thanks

How to (1) access the destination route (2) handle abstract routes

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 ...

  • A demonstration of how to access the destination path or route. Often you want to apply an Aspect Oriented middleware rule that will include or exclude a pattern of route names or path names or parameter names. I'm not sure if params includes all of these so an example of how to do this would be very valuable.
  • You often want to apply this to an abstract ui route so that a whole set of sub routes will have consistent middleware injected. This is really just a specialization of the pattern case but I think this very common case needs an example. It was what I went hunting for first when I looked over your documentation.

Adding these powerful examples should really help sell your concept.

Including module breaks <ui-view> rendering

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']);

package on npmjs is not up to date

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
		});
	}

plugins.js:2 TypeError: Cannot read property 'next' of undefined

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();
                    }
                });
            }]
        });

this.route is undefined

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

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.