Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Route Config "as" or "name" property #346

Closed
Dyljyn opened this issue Feb 22, 2016 · 3 comments
Closed

Route Config "as" or "name" property #346

Dyljyn opened this issue Feb 22, 2016 · 3 comments

Comments

@Dyljyn
Copy link

Dyljyn commented Feb 22, 2016

When using the DevServer of Webpack with a setup RouteConfig, I'm getting an error about both "as" and "name" property being set of a RouteDefinition, which I haven't.

webpack.config.js has not been changed from the default.

Code of normalizeRouteConfig: where the error comes from

if (config.as && config.name) {
    throw new exceptions_1.BaseException("Route config should contain exactly one \"as\" or \"name\" property.");
}

Component with RouteConfig

import {Component, View, Injectable} from 'angular2/core';
import {RouterOutlet, RouteConfig} from 'angular2/router';

import {App} from './app';
import {Test} from "./test";

@Component({
    selector: 'boot-auth',
})
@View({
    directives: [RouterOutlet],
    template: `
            <router-outlet></router-outlet>
    `
})
@RouteConfig([
    { path: ':at/...', component: App, as: 'App', name: null },
    { path: '/test', component: Test, as: 'Test', name: null }
])
export class BootAuth {}

Basic component

import {Component, View} from 'angular2/core';

@Component({
    selector: 'test'
})
@View({
    template: `
        Hello, this is test
    `
})
export class Test {
    constructor() {
        console.log('Test init');
    }
}

Anyone any idea how to fix this error?

@ericmartinezr
Copy link

The fix is really easy. As the error stated you should provide either as _OR_ name, not both. Consider too that as has been deprecated long ago, so you should use name

@Dyljyn
Copy link
Author

Dyljyn commented Feb 23, 2016

I tried with both cases, the name: null was to try having it as false. Didn't know 'as' has been deprecated though.

Just found out that using 'name' does indeed work, I forgot to put a # in the url http://localhost:3000/#/test.
Quick question: is there a way to not have to use the '#' with the devServer?

Thanks for your help.

@Dyljyn
Copy link
Author

Dyljyn commented Feb 23, 2016

Never mind the question: The answer was that default with webpack the HashLocationStrategy is used, changed to PathLocationStrategy to get the correct result.

bootstrap(BootAuth, [
    ...ENV_PROVIDERS,
    ...HTTP_PROVIDERS,
    ...ROUTER_PROVIDERS,
    provide(LocationStrategy, {useClass: PathLocationStrategy})
])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants