Comments (3)
We are having the same challenge at the moment. Have you ever found an elegant solution for this problem? The ideal way is to return bool value in beforeAction() that would instruct the controller to halt normal flow.
from chaplin.
In order to cancel the normal flow, we need to know that a redirect happened in the before action. The preferred way of initiating a redirect is the Controller#redirectTo
method (see http://docs.chaplinjs.org/chaplin.controller.html). It sets a redirected = true
flag on the controller:
https://github.com/chaplinjs/chaplin/blob/master/src/chaplin/controllers/controller.coffee#L52-L55
We’re checking for the redirected flag in the Dispatcher:
https://github.com/chaplinjs/chaplin/blob/master/src/chaplin/dispatcher.coffee#L133
In your cases you’re not using Controller#redirectTo
, but the redirect is triggered somewhere else. this is totally fine, but the redirected
flag is not set. As far as I can see, you can set this flag manually in your before action. This should stop the normal action from being called.
beforeAction: ->
unless loggedIn()
@redirected = true
mediator.publish('event that eventually triggers a redirect')
from chaplin.
Thanks @molily, this helps. It seems my problem was in using Chaplin utility utils.redirectTo()
method in beforeAction()
instead of Controller.redirectTo()
that sets redirected
flag.
from chaplin.
Related Issues (20)
- Access Control implementation
- View::render - return origin result from wrapped method HOT 5
- noWrap:true doesn't work properly in subviews when top-level element in template is not div HOT 2
- Model not set in Backbone Collection HOT 1
- Backbone 1.2.0 HOT 3
- jQuery#html => setHTML doesn't work in IE11 on win7 HOT 2
- (npm) Update to newer Backbone HOT 4
- itemView with nowrap=true doesn't work when template produces TR HOT 1
- delegate in itemview
- Internet Explorer reload on link with relative URL HOT 1
- Uncaught TypeError: Cannot read property 'undefined' of undefined HOT 8
- CollectionView insert new rows in opposite order to backbone collection models
- Incompatibility upgrading to 1.2.0 from 1.1.1 HOT 3
- Not working Backbone.js link in README.js HOT 1
- New release?
- ListenHash: remove 'model', 'collection' limitation
- Internet Explorer invalid pointer error
- Composer Doc is wrong in regards of `check` method
- Archive the organization
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chaplin.