Code Monkey home page Code Monkey logo

Comments (3)

artch avatar artch commented on June 16, 2024

The prefix is managed by $location service itself, it is not $routeSegment's responsibility. Moreover, links can be rewritten by the application or Angular itself, using its own knowledge about application configuration. It is all about separation of concerns.

from angular-route-segment.

airtonix avatar airtonix commented on June 16, 2024

I understand that.

The problem is that the URLs returned by your filters still need to work.

Without prefixing. They do not.

Currently, your filters only output the following :

define [
    'lodash'
    'angular'
    'text!./common/templates/one.tpl.html'
    'text!./common/templates/two.tpl.html'
    'angular-route-segment'
    ], (_, angular, tplOne, tplTwo) ->

        angular.module 'app.routes', [
            'ngRoute'
            'route-segment'
            'view-segment'
            ]

            .config [
                '$routeSegmentProvider'
                '$routeProvider'
                '$locationProvider'
                ($routeSegmentProvider, $routeProvider, $locationProvider) ->
                    $locationProvider.html5Mode false
                    $locationProvider.hashPrefix "!"

                    $routeSegmentProvider
                        .when '/one', 'one'
                        .segment 'one',
                            template: tplOne

                        .when '/two', 'two'
                        .segment 'two',
                            template: tplTwo

                    $routeProvider.otherwise
                        redirectTo: '/'
            ]
<a href="{{ 'one' | routeSegmentUrl }}">Some Segment</a>

results in

<a href="/one">Some Segment</a>

This is fine if your backend is handling all the redirects, except that :

...
                ($routeSegmentProvider, $routeProvider, $locationProvider) ->
                    $locationProvider.html5Mode false
                    $locationProvider.hashPrefix "!"
...

Meaning, there isn't, so it doesn't, therefore all urls generated by the filter/service should include the required characters to make it work under those configured circumstances.

from angular-route-segment.

artch avatar artch commented on June 16, 2024

routeSegmentUrl filter is just a wrapper around $routeSegment.getSegmentUrl(). If it was returning an URL with a hash, then this would not work:

$location.path($routeSegment.getSegmentUrl('one'));

You have to either rely on core Angular logic for rewriting html5 URLs in legacy hashbang mode (see "Html5 links rewriting" section at this docs page), implement your own URL rewrite logic, or just write like that:

<a href="#!{{ 'one' | routeSegmentUrl }}">Some Segment</a>

from angular-route-segment.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.