For example:
$stateProvider
.state('external', {
url: 'http://www.google.com',
})
url assumes that this is an internal state. I want it to be like href or something to that effect.
I have a navigation structure that will build from the ui-routes and I have a need for a link to go to an external link. Not necessarily just google, that's only an example.
Not looking for it in a link or as $state.href('http://www.google.com'). Need it declaratively in the routes config.
I transformed the accepted answer into one that assumes the latest version of AngularJS (currently 1.6), ui-router 1.x, Webpack 2 with Babel transpilation and the ng-annotate plugin for Babel.
And here's how the state may be configured:
Usage:
As mentioned in angular.js link behaviour - disable deep linking for specific URLs you need just to use
this will disable angularJS routing on a specific desired link.
You could use the
onEnter
callback:Edit
Building on pankajparkar's answer, as I said I think you should avoid overriding an existing param name. ui-router put a great deal of effort to distinguish between states and url, so using both
url
andexternalUrl
could make sense...So, I would implement an
externalUrl
param like so:And use it like so, with or without internal url:
Angular-ui-router doesn't support external URL, you need redirect the user using either
$location.url()
or$window.open()
I would suggest you to use
$window.open('http://www.google.com', '_self')
which will open URL on the same page.Update
You can also customize
ui-router
by adding parameterexternal
, it can betrue
/false
.Then configure
$stateChangeStart
in your state & handle redirection part there.Run Block
Sample Plunkr