Skip to content

feat(router): export ROUTES token as public api - #10983

Closed
sod wants to merge 1 commit into
angular:masterfrom
sod:routes-token-public
Closed

sod wants to merge 1 commit into
angular:masterfrom
sod:routes-token-public

Conversation

@sod

@sod sod commented Aug 22, 2016 •

Copy link
Copy Markdown
Contributor

What is the current behavior? (You can also link to an open issue here)

If you want to define your routes by a factory that compile-cli accepts, you can't use the bundles as the ROUTES token is not public.

What is the new behavior?

import {NgModule} from '@angular/core';
import {RouterModule, Routes, ROUTES} from '@angular/router';
import {BrowserModule} from '@angular/platform-browser';

export const _emptyRoutesArray = [];

export function _routes(): Routes {
    return [
        // your routes factory
    ];
}

@NgModule({
    imports: [
        BrowserModule,
        RouterModule.forRoot(_emptyRoutesArray),
    ],
    providers: [
        // provide your routes as a factory
        {provide: ROUTES, multi: true, useFactory: _routes},
    ],
    bootstrap: [
        MyAppComponent
    ],
})
export class MyAppModule {
}

Does this PR introduce a breaking change? (check one with "x")

[ ] Yes
[x] No

@sod

sod commented Aug 22, 2016

Copy link
Copy Markdown
Contributor Author

Related issue #10731

@sod
sod force-pushed the routes-token-public branch 3 times, most recently from 407e994 to 7e32def Compare August 23, 2016 07:16
To provide routes as factory like `{provide: ROUTES, multi: true, useFactory: _routes}` where `_routes` is a function that returns `Routes`
@sod
sod force-pushed the routes-token-public branch from 7e32def to 9b9a13b Compare August 23, 2016 08:50
@sod

sod commented Aug 24, 2016

Copy link
Copy Markdown
Contributor Author

@vsavkin may I export the token? or is there an alternative?

@mhevery

mhevery commented Aug 26, 2016 •

Copy link
Copy Markdown
Contributor

I think this is more complicated. The reason why ROUTES is private is because whenever routes are defined we also have to mark them for ANALYZE_FOR_ENTRY_COMPONENTS.

Are you saying that you would like to generate a list of routes dynamically? If so how can the template compiler know which of the components should be compiled?

(Also if you make something public we need documentation for it.)

@mhevery mhevery added action: review action: review The PR is still awaiting reviews from at least one requested reviewer and removed action: review labels Aug 26, 2016
@sod

sod commented Aug 26, 2016

Copy link
Copy Markdown
Contributor Author

Actually I just want to generate the URLs in runtime. A property that the AoT doesn't touch, but throws an error anyway :(

@sod

sod commented Sep 5, 2016 •

Copy link
Copy Markdown
Contributor Author

This works for now (rc.6) :D

import {RouterModule, Routes, __router_private__} from '@angular/router';

/* ... */

{provide: __router_private__.ROUTES, multi: true, useFactory: _routes},

@sod sod closed this Sep 5, 2016
@sod

sod commented Sep 5, 2016

Copy link
Copy Markdown
Contributor Author

No, doesn't work. I guess I just surrender and write the routes statically into javascript for now.

@angular-automatic-lock-bot

Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot Bot locked and limited conversation to collaborators Sep 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: review The PR is still awaiting reviews from at least one requested reviewer cla: yes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants