0

I'm trying to build a shell manually trying to figure out how it works

Structure:

- application(php stuff) - webroot -- app --- app.js -- templates --- main ---- login ----- login.html index.html (with angularjs libs) 

app.js:

function config($routeProvider){ $routeProvider .when("/login",{ templateUrl: "../templates/main/login/login.html" }) .otherwise({ redirectTo:"/other" }); } angular .module("app", ["ngRoute", "ngResource"]) .config(config); 

login:

<div>LOGIN test template</div> 

"/other" doesn't exit. Besides I tried different pathes as: templateUrl: "templates/main/login/login.html" templateUrl: "webroot/templates/main/login/login.html"

By the way the url comes with an "#" (eg. nameDomain.com/#/login, but it should be nameDomain.com/#login) but angularjs seems allow only /nameUrlTemplate

1 Answer 1

1

Take a look at Angular's docs for routeProvider, as this should clear up some of your confusion.

I think what you want to do here is use an existing route in your .otherwise, because since /other isn't defined anywhere, Angular won't know what do you with it:

var app = angular.module('app', ['ngRoute', 'ngResource']); app.config(function config($routeProvider) { $routeProvider .when('/', { templateUrl: '../templates/main/index.html' }) .when('/login', { templateUrl: '../templates/main/login/login.html' }) .otherwise({ redirectTo: '/' }); }); 

I believe this should give you the effect you're looking for. Obviously you can tweak it as you see fit, if for example you wanted to have a 404 route/template for anything that you don't define. As it stands, this will always fall back to the homepage for a particular route that doesn't exist. This gets more complicated when you're considering users and logged in/out states, but this is more of a proof-of-concept.

Additionally, ngRoute will render by default a URL in the format of /#/foo since that is using a hashbang-style format, which enables crawlers for search engines to be able to parse and read the various pages/states of a JavaScript webpp. What you're referring to is a document fragment, which are not indexable by crawlers. You can read more about the differences on Google's Webmaster docs.

Sign up to request clarification or add additional context in comments.

2 Comments

What's wrong with my WHEN .when('/login',{ templateUrl: '../templates/main/login/login.html' })
additionally: I'd like to have /#login instead /#/login

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.