Could someone explain how quasar-components should be used? - quasar

I am new to Quasar framework. Could someone explains how quasar-components should be used?
1)Where should they be stored?
2)What will be the folder structure if more components are used for a single app?
3)How will be the router.js file be?

You have information about the structure of a quasar project here
As you can see all the components you need are saved in the templates folder.
The router.js will be according to your needs. I recommend that you look at this tutorial on vue-router that is very complete and will clarify things to you.
For example, the contents of my router.js would be as follows:
import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)
function load (component) {
return () => System.import(`components/${component}.vue`)
}
const router = new VueRouter({
routes: [
{
path: '/',
component: load('Index')
}, // Default
{
path: '/login',
component: load('Login')
},
{
path: '/home',
component: load('Home'),
meta: {
requiresAuth: true
}
},
{
path: '/settings',
component: load('Settings')
},
{
path: '/session',
component: load('Session'),
meta: {
requiresAuth: true
}
},
{
path: '/node/:id',
component: load('Node'),
meta: {
requiresAuth: true
}
},
{
path: '/admin/:action',
component: load('Admin'),
meta: {
requiresAuth: true
}
},
{
path: '/template/:id',
component: load('Template'),
meta: {
requiresAuth: true
}
},
{
path: '/output/:id',
component: load('Output'),
meta: {
requiresAuth: true
}
},
{
path: '/form/:id',
component: load('Form'),
meta: {
requiresAuth: true
}
},
{
path: '/file/:id',
component: load('File'),
meta: {
requiresAuth: true
}
},
{
path: '*',
component: load('Error404')
}
]
})
export default router
Then in the component.vue I navigate to another route:
HTML Inside <template>
<button v-if="session !== null" #click="goPath('/home')"><i>home</i></button>
MODEL Inside methods I have the function:
goPath (url) {
this.$router.push(url)
}
As I said you will have other needs and I do not think this example applies but to give you an idea.

Related

angular routerlink redirect to 404

I have a problem with routerlinks in angular. I use routerlinks to redirect to the next page in my application.
If I start my applicaton with ng serve everything works fine. If I build my application with ng build --prod routerlinks return in some cases a 404.
The exact problem:
I am using a routeroutlet to display the different components. If I click on a routerlink which is in a component that is displayed in the routeroutlet I get a 404. If I use a routerlink that is in my component.html outside of the routeroutlet everything works fine.
That is my routeroutlet
<div class="">
<router-outlet></router-outlet>
</div>
That is my routerlink
<a [routerLink]="['overview']" [queryParams]="{categorie:'Shopping',subcategorie:'topcategorie'}"
class="btn btn-primary searchbutton">suchen</a>
and that are my routes:
const routes: Routes = [
{ path: 'overview/:categorie/:subcategorie', component: OverviewComponent },
{ path: 'overview', component: OverviewComponent },
{ path: 'overview/:brand', component: OverviewComponent },
{ path: 'overview/:product', component: OverviewComponent },
{ path: 'coupons', component: CouponComponent },
{ path: 'impressum', component: ImpressumComponent },
{ path: 'datenschutz', component: DatenschutzComponent },
{ path: 'details/:id', component: ProductDetailsComponent },
{ path: 'home', component: LandingpageComponent },
{ path: '', component: LandingpageComponent }
];
#NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }

Angular 7 - Load images before changing route

I'm currently working on a portfolio. My intention is to only change the route ("portfolio" and its child route "all" which is displayed immediately) as soon as the images on that specific route are fully loaded. When the route was clicked as progress bar from Angular Materials shall be displayed.
Since I'm a beginner with angular I unfortunately can't provide any code, but my app-routing.module.
Browsing the internet I found a similar question, which I didn't really understand:
https://forum.vuejs.org/t/load-images-before-changing-route/11479
App-Routing.Module:
const routes: Routes = [
{ path: '', component: HomeComponent },
{ path: 'about', component: AboutComponent},
{ path: 'portfolio', component: PortfolioComponent, children: [
{ path: '', redirectTo: 'all', pathMatch: 'full'},
{ path: 'all', component: AllComponent},
{ path: 'wedding', component: PortfolioweddingComponent},
{ path: 'adventure', component: PortfolioadventureComponent},
]},
{ path: 'book-me', component: BookMeComponent},
{ path: 'book-me/wedding', component: WeddingComponent},
{ path: 'book-me/adventuresession', component: AdventuresessionComponent},
];
#NgModule({
imports: [RouterModule.forRoot(routes, {scrollPositionRestoration: 'enabled'}), RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }

In Angular2, Use Service to get application routes

I have angular 6 application. I have requirements to get dynamic routes, logic of which is been sorted. I have AppRoutingService class which has method getAppRoutes() returning static route collection. I need this to be called app RouterModule.forRoot(...), the objective if can manage to inject static routes using service class, then I can assemble dynamic routes from database in this static list.
In doing so I am getting error.
error
Uncaught TypeError: Cannot read property 'appRoutingService' of undefined
at main.js:1055
at Module../src/app/modules/application/app-routing.module.ts (main.js:1065)
at __webpack_require__ (runtime.js:84)
App routing class
import { AppRoutingService } from './services/routing/app-routing-service';
#NgModule({
imports: [
RouterModule.forRoot(this.appRoutingService.getAppRoutes()) // here i need to inject appRoutingService method... need help here....???
],
exports: [
RouterModule
]
})
export class AppRoutingModule {
constructor(
private router:Router,
private appRoutingService: AppRoutingService
) {
}
}
App Routing Service class
#Injectable()
export class AppRoutingService{
public RouteCollection: Routes = [
{
path:'',
redirectTo: 'dashboard',
pathMatch: 'full'
},
{
path: '',
component: WebLayoutComponent,
children:[
{
path:'dashboard',
loadChildren: '../dashboard/dashboard.module#DashboardModule'
},
{
path:'survey',
loadChildren: '../survey/survey.module#SurveyModule'
}
]
},
{
path:'**',
component:PageNotFoundComponent
}
];
public getAppRoutes(): Route[]
{
return this.RouteCollection;
}
}
You are using the keyword "this" in a wrong place. there is no "this" in that context, because it is outside of a class. Since "this" === undefined, then the reason behind the error becomes clear, because you are trying to fetch the appRoutingService from undefined.
#NgModule({
imports: [
RouterModule.forRoot(AppRoutingService.getAppRoutes()) // here i need
to inject appRoutingService method... need help here....???
],
exports: [
RouterModule
]
})
And make the AppRoutingService method and variable static.
public static RouteCollection: Routes = [
{
path:'',
redirectTo: 'dashboard',
pathMatch: 'full'
},
{
path: '',
component: WebLayoutComponent,
children:[
{
path:'dashboard',
loadChildren: '../dashboard/dashboard.module#DashboardModule'
},
{
path:'survey',
loadChildren: '../survey/survey.module#SurveyModule'
}
]
},
{
path:'**',
component:PageNotFoundComponent
}
];
public static getAppRoutes(): Route[]
{
return AppRoutingService.RouteCollection;
}

Routing in Angular 4

I have an issue with routing in my app. In my local all works right but not on the server. The program has the following routes:
const appRoutes: Routes = [
{ path: '', component: HomeComponent },
{ path: 'login', component: LoginComponent },
{ path: 'register', component: RegisterComponent },
{ path: 'thankyou', component: ThankyouComponent },
{ path: 'home', component: UserHomeComponent, canActivate: [AuthGuard] },
{ path: 'publish', component: PublishComponent, canActivate: [AuthGuard] },
{ path: '**', component: PageNotFoundComponent }
];
The root route always works.
If on my computer I send request directly, for example, the route:
http://localhost:4200/publish
Assuming that I have logged in there are no problems loading it. But if execute that route in server with the route:
http://myserver/mypath/dist/publish
It doesn't find the route.
I modified index.html as well, to execute on server.
<base href="/"> by <base href="/mypath/dist/">
If I execute that route by the template html using directive
routerLink="/publish"
It works fine.
Does anyone know why this happens?
Your webserver needs to be configured to reroute requests to your index.html, excluding assets.
For nginx, add this inside your server block of your nginx.conf or your site config:
location / {
try_files $uri $uri/ /path/to/index.html;
}
For apache, check this answer.
Here is an example of a file that creates a routing structure for the routes to hit when they are put into the url. So far I have not seen anything in your question that suggests you are actually handling routes from outside your app. In other words, how does some url from your server know where to go if you haven't defined a route that would be typed in as a url? Seems you don't have a root path. That's what I've been driving at.
import { Routes, RouterModule } from '#angular/router';
import { SomeComponent } from 'app/components/some-component';
import { Path1Component } from 'app/components/path1-component';
import { Path2Component } from 'app/components/path2-component';
import { Path3Component } from 'app/components/path3-component';
const MyRoutes: Routes = [
{
path: 'root/',
component: SomeComponent,
children: [
{
path: 'path1',
component: Path1Component
},
{
path: 'path2',
component: Path2Component
},
{
path: 'path3',
component: Path3Component
},
{
path: '**', // default path
component: Path2Component
}
],
}
];
#NgModule({
imports: [
RouterModule.forChild(MyRoutes)
],
exports: [
RouterModule
]
})
export class MyRouting { }
I have found the solution in this site https://github.com/angular/angular/issues/11884
but I don't have full access to server. I have switched in root module to HashLocationStrategy as the angular guide says here https://angular.io/guide/router#appendix-locationstrategy-and-browser-url-styles
and it works!

Replace semicolon, id and equal sign in URL in an Angular2 app

I am trying to set URLs to my items got via json.
So I have a structure like that:
<div class="releases-component">
<div *ngFor="let release of releases" [routerLink]="['/releases', { id:release.id }]">
<img src="{{release.image}}" alt="Image release">
<h3>{{release.name}}</h3>
<span>{{release.year}}</span>
</div>
</div>
And I've got json of type:
[
{
"id":"release-1",
"name": "Release1 name",
"image": "./cover1.jpg",
"year": "2014"
},
{
"id":"release-2",
"name": "Release2 name",
"image": "./release2.jpg",
"year": "2015"
}
]
My router:
const routes: Routes = [
{ path: '', component: HomeComponent },
{ path: 'releases', component: ReleasesComponent },
{ path: 'distro', component: DistroComponent },
{ path: 'contacts', component: ContactsComponent }
];
The problem is that when I click on any *ngFor generated div I get url like
http://localhost:3000/releases;id=release-1
And I want it to look like
http://localhost:3000/releases/release-1
Didn't manage to find a working solution in Angular2 to me.
There are few small syntax mistakes in the code above, here is the code with the fixes.
Structure:
<div class="releases-component">
<div *ngFor="let release of releases" [routerLink]="['/releases',release.id ]">
<img src="{{release.image}}" alt="Image release">
<h3>{{release.name}}</h3>
<span>{{release.year}}</span>
</div>
</div>
Router:
const routes: Routes = [
{ path: '', component: HomeComponent },
{ path: 'releases/:id', component: ReleasesComponent },
{ path: 'distro', component: DistroComponent },
{ path: 'contacts', component: ContactsComponent }
];
Here is a one page similar working example plunkr code: http://plnkr.co/edit/UyNkK9?p=preview,
you can see the url changes on this plunkr url,
http://run.plnkr.co/plunks/UyNkK9/
Here is how the url will look after you click on releases, http://run.plnkr.co/plunks/UyNkK9/releases/release-1
html:
<div class="releases-component">
<div *ngFor="let release of releases"
(click)=onSelect(release)>
<img src="{{release.image}}" alt="Image release">
<h3>{{release.name}}</h3>
<span>{{release.year}}</span>
</div
</div>
routes:
const routes: Routes = [
{ path: '', component: HomeComponent },
{ path: 'releases/:id', component: ReleasesComponent },
{ path: 'distro', component: DistroComponent },
{ path: 'contacts', component: ContactsComponent }
];
component:
import {Router} from '#angular/router';
...
...
constructor(private router: Router) {}
onSelect(release): any {
this.router.navigate(['/release', release.id]);
}