Angular 2 RC5子路由问题

时间:2016-08-12 20:48:44

标签: angular routing router

我正在尝试让子路由工作,这是我得到的错误:

package com.moneylife.stashinvaders;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.input.GestureDetector;
import com.badlogic.gdx.math.Vector2;

public class Player {
    Vector2 position;
    Texture texture;
    int speed = 500;
    float deltaTime;
    int screenWidth, screenHeight;
    boolean MovingRight = false, MovingLeft = false;


    public Player(int ScreenW, int ScreenH){
        Gdx.input.setInputProcessor(new GestureDetector(new MyGestureDetector()));
        texture = new Texture("bazookaman.png");
        position = new Vector2(Gdx.graphics.getBackBufferWidth() / 2 - texture.getWidth() / 2, 0);
        screenWidth = ScreenW;
        screenHeight = ScreenH;
    }

    public void update(){
        deltaTime = Gdx.graphics.getDeltaTime();
        if (MovingRight){
            position.x += speed * deltaTime;
        }
        if (MovingLeft){
            position.x -= speed * deltaTime;
        }
    }

    public void draw(SpriteBatch spriteBatch){
        spriteBatch.draw(texture, position.x, position.y);
    }


    public class MyGestureDetector implements GestureDetector.GestureListener {
        @Override
        public boolean touchDown(float x, float y, int pointer, int button) {
            if (x > position.x) {
                MovingRight = true;
            }
            if (x < position.x){
                MovingLeft = true;
            }
            return false;
        }

        @Override
        public boolean tap(float x, float y, int count, int button) {
            return false;
        }

        @Override
        public boolean longPress(float x, float y) {
            return false;
        }

        @Override
        public boolean fling(float velocityX, float velocityY, int button) {
            return false;
        }

        @Override
        public boolean pan(float x, float y, float deltaX, float deltaY) {
            return false;
        }

        @Override
        public boolean panStop(float x, float y, int pointer, int button) {
            MovingLeft = false;
            MovingRight = false;
            return false;
        }

        @Override
        public boolean zoom(float initialDistance, float distance) {
            return false;
        }

        @Override
        public boolean pinch(Vector2 initialPointer1, Vector2 initialPointer2, Vector2 pointer1, Vector2 pointer2) {
            return false;
        }

        @Override
        public void pinchStop() {

        }

    }
}

这是我的app.modules.ts

EXCEPTION: Error: Uncaught (in promise): Error: Cannot match any routes: 'settings'

这是我的app.routes.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
import { routeComponents, routing, appRoutingProviders } from './app.routes';


@NgModule({
    declarations: [
        AppComponent,
        routeComponents
    ],
    imports: [
        BrowserModule,
        CommonModule,
        FormsModule,
        routing
    ],
    providers: [ appRoutingProviders ],
    entryComponents: [AppComponent],
    bootstrap: [AppComponent]
})
export class AppModule {

}

这是我的settings.routes.ts

import { Routes, RouterModule } from '@angular/router';
import { DashboardComponent } from './dashboard/';
import { settingsRoutes, settingsComponents } from './settings/';

const appRoutes: Routes = [
    { path: '', redirectTo: 'dashboard', pathMatch: 'full'},
    { path: 'dashboard', component: DashboardComponent },
    ...settingsRoutes
];

export const appRoutingProviders: any[] = [

];

export const routeComponents: any[] = [
    DashboardComponent,
    ...settingsComponents
];

export const routing = RouterModule.forRoot(appRoutes, {useHash: true});

**如果我从settings.routes.ts文件中删除此行,则没有错误,它允许我转到设置路线:

import { Routes } from '@angular/router';
import { SettingsComponent } from "./settings.component";
import { DashboardSettingsComponent } from "./dashboard-settings/dashboard-settings.component";

export const settingsRoutes: Routes = [
    {
        path: 'settings',
        component: SettingsComponent,
        children: [
            { path: 'dashboard-settings', component: DashboardSettingsComponent }
        ]
    }
];

export const travelSettingsComponents = [
    SettingsComponent,
    DashboardSettingsComponent
];

0 个答案:

没有答案