Comments (14)
I speak malayalam, my neighbouring state speaks tamil, my country speaks more than 1600 languages...... dare not to learn any one of those... or you will end up hearing words those are bolder than that you have ever heard in your lifetime...
This 26 letter language of yours, is not our mother tongue, yet we have mastered it so well.. so respect that you MF
from ui-router.
LOL
from ui-router.
$routeProvider is a shim the implements the current AngularJS $route / $routeProvider API on top of $stateProvider, to make it easier for people to transition applications to $stateProvider step by step -- it simply fudges the route definition into a state definition by making up a name, and some other small things.
Current AngularJS $routeProvider is also monolithic, it that it handles everything internally that in our code is split up into multiple services:
- watching $location and triggering something when it matches a pattern / rule -> $urlRouterProvider
- defining the syntax for url patterns and parameter placeholders -> $urlMatcherFactory
- loading templates via $http / $templateCaache -> $templateFactory
- managing and exposing the current route -> $stateProvider
- asynchronous resolving of view dependencies and making the result available to the view directive -> currently $stateProvider, maybe factor out into separate $view service?
So $urlRouterProvider simply has the responsibility of watching $location, and when it changes running through a list of rules one by one until one matches. How exactly "matching" is defined and what happens when a rule matches is up to that rule; at the lowest level its just a function that returns true if it has handled the URL. However there is support built on top of this for rules that are RegExps, as well as path patterns with placeholders (as used by state.url) that are compiled into rules via $urlMatcherFactory. $urlRouterProvider also supports redirects.
As it stands $urlRouterProvider should already be faster than the corresponding code in $routeProvider, because it doesn't re-parse url patterns on every location change, but instead hangs on to the compiled UrlMatcher objects.
(I've got a TODO in the code to improve this further by taking static prefixes into account to be able to skip blocks of rules -- for example if there is a sequence of 8 URL patterns that all start with "/contacts/", but the current $location starts with "/users/", there's clearly no point in attempting to match those 8 rules. Static prefixes also allow rules to be re-ordered for further optimizations. I'm not sure these optimizations are actually necessary yet, but a moderately complex application can easily have hundreds of rules that need to be processed every time $location changes.)
from ui-router.
@jakekemple "Shim" and "Fudges" are the correct developer words. They make perfect sense to me.
@ksperling, I am still having trouble understanding your comment though.
It opens with:
$routeProvider is a shim the implements ...
("the implements" should be "that implements")
Then it continues:
Current AngularJS $routeProvider is also monolithic ...
So is it monolithic, or is it a shim (meaning a very thin layer mostly emulating something else)?
I think you may mean "$urlRouterProvider is a shim that implements the current AngularJS $route / $routeProvider API...".
So we should probably use $urlRouterProvider in preference to $route / $routeProvider, but even better would be to just stick to $stateProvider only.
from ui-router.
Ok that clears it up, so in the sample app you are just using each one to
show them off but in a real app users may not use either.
from ui-router.
If in a real app, I do not need to use '$routeProvider', '$urlRouterProvider', then with just '$stateProvider', how can I do stuff like -
.when('/', {
template: 'hello'
}
or
.when('/', {
redirectTo: '/helloWorld'
}
from ui-router.
You need to use $urlRouterProvider for doing redirects. This is all done with $urlRouterProvider.when(match, handler). Match can be
- a RegExp
- a UrlMatcher
- a String (gets compiled into a UrlMatcher via $urlMatcherFactory)
The handler is generally a function, this function gets invoked if $location matches. It can return - falsy to indicate that the rule didn't match after all, then $urlRouter will continue trying to find another one that matches
- a String, which is treated as a redirect and passed to $location.url()
- nothing or any truthy value tells $urlRouter that the url was handled
The handler can also be a string, which is treated as a redirect, and is interpolated according to the syntax of match (i.e. like String.replace() for RegExp, or like a UrlMatcher pattern otherwise)
There's also a lower-level function $urlRouterProvider.rule() that takes an arbitrary function that gets passed $location. Probably best to look at the source at this point; documenting all this is still on my todo list.
from ui-router.
See my comment on the other issue where you posted this question -- urlRouter rules are tested against $location in the order they are registered.
from ui-router.
so, How can I find the api document ?? I couldn't find it in angualrJs.org
from ui-router.
I should probably write some wiki for urlRouter :/
from ui-router.
@timkindberg Let me know if you need help. I'm usually idling on #angularjs.
from ui-router.
@ksperling and @nateabele please review my docs for $urlRouterProvider and $urlMatcherFactory.
https://github.com/angular-ui/ui-router/wiki/URL-Routing#urlrouterprovider
https://github.com/angular-ui/ui-router/wiki/URL-Routing#urlmatcherfactory-and-urlmatchers
from ui-router.
Looks good!
from ui-router.
So is it monolithic, or is it a shim (meaning a very thin layer mostly emulating something else)?
@rjmunro The comment refers to two different things. The former is the implementation in Angular core. The latter was UI Router's (no-longer-supported) compatibility layer for people migrating from ngRoute.
Since $routeProvider
no longer ships with any supported version of UI Router, I think this thread is moot at this point.
from ui-router.
Related Issues (20)
- Resolve triggering twice HOT 1
- No services listed in 2.x docs HOT 2
- Optional params included on all similar routes HOT 1
- child states of lazy loaded future states get stuck in stateQueue HOT 1
- Transition Rejection : while upgrading angularjs from 1.5 to 1.8 using angular-route:1.0.0 HOT 1
- this.parent.parameters() is not a function while Upgrading angular-ui-router from 0.2.15 to 1.0.29
- I used transition.onStart() instead of stateChangeStart, but it shows .onStart is not a function.
- Documentation Broken HOT 1
- Access states' custom data-object in component
- dependency's version is not the same
- Update @uirouter/core dependency to 6.0.9 HOT 3
- Support for Standalone components HOT 1
- Is this library still being maintained? HOT 1
- V1.1.0 - TypeError: Cannot read properties of undefined (reading 'inherit') HOT 36
- AngularJS v1.3.5 - Page reloads on route change after npm install for latest build.
- Angular: StateService injected in custom library results in R3InjectorError HOT 1
- ui-router
- https://github.com/angular-ui/ui-router/tree/e8694114594d5aaf9f40e27b8ba194bca85595de
- str.split is nto a function HOT 1
- Please release the 1.1.0 version as soon as possible. HOT 6
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 ui-router.