Giter Site home page Giter Site logo

Comments (14)

 avatar commented on May 22, 2024 21

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.

nateabele avatar nateabele commented on May 22, 2024 9

LOL

English

from ui-router.

ksperling avatar ksperling commented on May 22, 2024 6

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

rjmunro avatar rjmunro commented on May 22, 2024 1

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

timkindberg avatar timkindberg commented on May 22, 2024

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.

udayms avatar udayms commented on May 22, 2024

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.

ksperling avatar ksperling commented on May 22, 2024

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.

ksperling avatar ksperling commented on May 22, 2024

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.

chenhui5416 avatar chenhui5416 commented on May 22, 2024

so, How can I find the api document ?? I couldn't find it in angualrJs.org

from ui-router.

timkindberg avatar timkindberg commented on May 22, 2024

I should probably write some wiki for urlRouter :/

from ui-router.

nateabele avatar nateabele commented on May 22, 2024

@timkindberg Let me know if you need help. I'm usually idling on #angularjs.

from ui-router.

timkindberg avatar timkindberg commented on May 22, 2024

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

nateabele avatar nateabele commented on May 22, 2024

Looks good!

from ui-router.

nateabele avatar nateabele commented on May 22, 2024

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)

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.