Added support of redirectTo instruction at segment params.#16
Added support of redirectTo instruction at segment params.#16wingedfox wants to merge 11 commits intoartch:masterfrom
Conversation
Syntax:
$routeSegmentProvider
.when('/section', 's1')
.when('/section/index', 's1.idx')
.segment('section', {
redirectTo: 'section/index'
})
.within()
.segment('idx', {
templateUrl: '/views/segment/idx.html'
});
* multiple views per segment, based on the dependencies
* support for ng-if, ng-switch and other directives based on the transclusion
* scope-based segment names
Example:
Routes:
```javascript
$routeSegmentProvider
.when('/page', 'page')
.when('/page/:view1,:view2', 'page.view')
.when('/page/:view1', 'page.view')
.segment('page', {
redirectTo: '/page/main',
templateUrl : '/views/layout/page.html',
controller : 'PageCtrl'
})
.within()
.segment('view', {
dependencies : ['view1', 'view2'],
templateUrl : {
main : '/views/page/main.html',
other : '/views/page/other.html',
more : '/views/more.html'
},
controller : {
main : 'MainCtrl',
other : 'TextCtrl',
more : 'ChartCtrl'
}
});
```
View:
```html
<div class="page"
<div class="view" ng-class="{left: isDouble(), main: isSingle()}">
<div class="content" app-view-segment="segment1"></div>
</div>
<div class="right view" ng-if="isDouble()">
<div class="frame" app-view-segment="segment2"></div>
</div>
</div>
```
Controller:
```javascript
function($rootScope, $scope, $location, $routeSegment, $routeParams, $animate) {
$scope.$watch(function () {return $routeParams}, function (n, o) {
$scope.$windowMode = (n.window1 && n.window2) ? 2 : 1;
}, true);
$scope.segment1 = '1.view1';
$scope.segment2 = '1.view2';
/**
* @return {Boolean} - true if only one window is enabled
*/
$scope.isSingle = function isSingle () {
return $scope.$windowMode == 1;
}
/**
* @return {Boolean} - true if two windows are enabled
*/
$scope.isDouble = function isDouble () {
return $scope.$windowMode == 2;
}
}
```
|
Great work! |
|
@wingedfox Your provided example could be easily rewrited like this: $routeSegmentProvider
.when('/section', 's1.idx') // you can use deep-level segment here
.when('/section/index', 's1.idx')
.segment('section', {
template: '<div app-view-segment="1"></div>'
})
.within()
.segment('idx', {
templateUrl: '/views/segment/idx.html'
});There is no need in separate $routeProvider.when('/invalidUrl', {redirectTo: '/validUrl'});
$routeSegmentProvider.when('/validUrl', 'segment')
.segment('segment', ...);But your latter commits look really interesting. Could you please provide tests on it? |
|
@artch, even if I can buy a piglet, I prefer not to do that :) In your example you'll have all the relative links broken. for sure this does not mean that the following will be correct at any given moment when a root page is added inner redirects will remain intact. I'll try to add the tests, but I don't work on that project anymore so first I'll have to remember what's going on there. |
|
A bit unclear for me. You wrote: $routeSegmentProvider
.when('/section', 's1')
.when('/section/index', 's1.idx')
.segment('section', {
redirectTo: 'section/index'
})This piece of configuration is identical to: $routeSegmentProvider
.when('/section', 's1.idx')
.when('/section/index', 's1.idx')Isn't it? |
|
Following your way link from template with /section in the address bar it will point to /b When using redirects, you'll never see /section in the address bar, you always will be redirected to /section/index. |
|
OK, why not to use built-in angular |
|
For me, this is the vital case. instructions, placed somewhere out of context, where the section is defined. Here I have to change 3 lines to make /reports/market/value/sum default report. |
|
I see. How do you assign segments to URLs in the case of these 5 routes? |
Useful for managing external and internal redirects within a route definitions
Syntax: